0

My php login form doesn't work, i can't find the problem. I tested the sql query in php with fixed values and it works (without the button). So my guess is that its the submit button.

The database works fine, i can select items from it but i can't insert data with a submit form.

<?php

session_name('LoginForm');
@session_start();

error_reporting(0);
include("config.php");

?>


<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
        <?php include_once("analyticstracking.php"); ?>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>test</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" sizes="57x57" href="/img/apple-icon-57x57.png">
        <link rel="apple-touch-icon" sizes="60x60" href="/img/apple-icon-60x60.png">
        <link rel="apple-touch-icon" sizes="72x72" href="/img/apple-icon-72x72.png">
        <link rel="apple-touch-icon" sizes="76x76" href="/img/apple-icon-76x76.png">
        <link rel="apple-touch-icon" sizes="114x114" href="/img/apple-icon-114x114.png">
        <link rel="apple-touch-icon" sizes="120x120" href="/img/apple-icon-120x120.png">
        <link rel="apple-touch-icon" sizes="144x144" href="/img/apple-icon-144x144.png">
        <link rel="apple-touch-icon" sizes="152x152" href="/img/apple-icon-152x152.png">
        <link rel="apple-touch-icon" sizes="180x180" href="/img/apple-icon-180x180.png">
        <link rel="icon" type="image/png" sizes="192x192"  href="/img/android-icon-192x192.png">
        <link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="96x96" href="/img/favicon-96x96.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
        <link rel="manifest" href="/img/manifest.json">
        <meta name="msapplication-TileColor" content="#ffffff">
        <meta name="msapplication-TileImage" content="/img/ms-icon-144x144.png">
        <meta name="theme-color" content="#ffffff">


        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

        <link rel="stylesheet" href="css/main.css">
        <link href='http://fonts.googleapis.com/css?family=Roboto:400,300,500' rel='stylesheet' type='text/css'>
        <link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
        <script src="js/jquery-1.8.2.min.js"></script>
        <script src="js/jquery.validate.min.js"></script>
        <script src="js/main.js"></script>




    </head>
    <body>

            <div id="login-form" class="login-form" name="form1">
                <ul>
                        <li><a class="active" href="index.php">Home</a></li>
                        <li><a href="register.php">register</a></li>
                </ul>

                <?php
                    $servername = "localhost";
                    $username = "root";
                    $password = "";
                    $dbname = "test";

                    // Create connection
                    $conn = mysqli_connect($servername, $username, $password, $dbname);
                    // Check connection
                    if (!$conn) {
                        die("Connection failed: " . mysqli_connect_error());
                    }
                // If form submitted, insert values into the database.
                     if ( isset($_POST['submit']) ) {
                        $email = $_POST['email'];                   
                        $password = $_POST['password'];                 
                        $name = $_POST['name'];                 
                        $phone = $_POST['phone'];               
                        $student =$_POST['student'];                                    
                        $city = $_POST['city'];                                     
                        $street = $_POST['street'];                                         
                        $address = $_POST['address'];                                       
                        $zipcode = $_POST['zipcode'];


                        $password = mysqli_real_escape_string($conn, $password);                    
                        $name = mysqli_real_escape_string($conn, $name);                
                        $phone = mysqli_real_escape_string($conn, $phone);              
                        $student = mysqli_real_escape_string($conn, $student);                                  
                        $city = mysqli_real_escape_string($conn, $city);                                    
                        $street = mysqli_real_escape_string($conn, $street);                                        
                        $address = mysqli_real_escape_string($conn, $address);                                  
                        $zipcode = mysqli_real_escape_string($conn, $zipcode);


                        $query = "INSERT into php_users_login (email, password, name, phone, student, city, street, address, zipcode)) VALUES ('$email', '$password)', '$name', '$telefoon', '$student', '$city','$street','$address','$zipcode')";
                        $result = mysqli_query($conn,$query);
                        if ($res) {
                            $errTyp = "success";
                            $errMSG = "Successfully registered, you may login now";
                            unset($name);
                            unset($email);
                            unset($pass);
                           } else {
                            $errTyp = "danger";
                            $errMSG = "Something went wrong, try again later..."; 
                           }
                     }
                ?>
                <div class="form-content" >
                <h1>Registreren</h1>
                <form name="registration" action="" method="post">
                <table>
                <tr>
                    <td>E-mail</td>
                    <td><input type="email" name="email" placeholder="E-mail" required /></td>
                </tr>
                <tr>
                    <td>password:</td>
                    <td><input type="password" name="password" placeholder="password" required /></td>
                </tr>
                <tr>
                    <td>name:</td>
                    <td><input type="name" name="name" placeholder="name" required /></td>
                </tr>
                <tr>
                    <td>phone:</td>
                    <td><input type="phone" name="phone" placeholder="phone" required /></td>
                </tr>
                <tr>
                    <td>Student:</td>
                    <td><input type="student" name="student" placeholder="student" required /></td>
                </tr>
                <tr>
                    <td>city:</td>
                    <td><input type="city" name="city" placeholder="city" required /></td>
                </tr>
                <tr>
                    <td>street:</td>
                    <td><input type="street" name="street" placeholder="street" required /></td>
                </tr>
                <tr>
                    <td>address:</td>
                    <td><input type="address" name="address" placeholder="address" required /></td>
                </tr>
                <tr>
                    <td>zipcode:</td>
                    <td><input type="zipcode" name="zipcode" placeholder="zipcode" required /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><button type="submit" class="submit" name="submit">Register</button></td>
                </tr>
                </table>
                </form>
                </div>



            </div>   
    </body>
</html>
4
  • paste your error here Commented Jan 24, 2017 at 9:23
  • Echo out he $query and then copy this query. Paste it in phpmyadmin and run. Copy the error and then paste it here. Commented Jan 24, 2017 at 9:25
  • Try print_r($_POST); and see what vars are passed. Also I think the submit button doesn't need a name, type is enough. Commented Jan 24, 2017 at 9:27
  • 1
    Found the problem, it was the query. Commented Jan 24, 2017 at 9:27

2 Answers 2

1

Your code is -

$query = "INSERT into php_users_login (email, password, name, phone, student, city, street, address, zipcode)) VALUES ('$email', '$password)', '$name', '$telefoon', '$student', '$city','$street','$address','$zipcode')";

Here an extra ) in column field city, street, address, zipcode)) and another is your values VALUES ('$email', $password) Probably that was the problem on inserting. Please remove the extra braces or try the following code -

$query = "INSERT into php_users_login (email, password, name, phone, student, city, street, address, zipcode) VALUES ('$email', '$password', '$name', '$telefoon', '$student', '$city','$street','$address','$zipcode')"
Sign up to request clarification or add additional context in comments.

Comments

0

Like @Md said. It was a database error.. The database error is not display in php code. You can use try {}catch(){}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.