isset($ _ POST ['submit']在提交表单后未设置

I'm new to php and I'm trying to register a user to a database using a form.

This is the code for the form (using the bootstrap framework):

<form class="form-horizontal" role="form" method="POST" action="connectivity-reserve.php">
                <div class="form-group">
                    <label class="col-sm-2 control-label">Customer's name</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                        <input type="text" class="form-control" id="Customername" name="Customername" placeholder="Customer name">
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">Password</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                        <input type="password" class="form-control" id="pwd" name="pwd" placeholder="Password">
                        </div>
                    </div>
                </div>

                </div>
                 <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" name ="submit" class="btn btn-primary">Reserve</button>
                    <button type="button" class="btn btn-default btn-sm"
                   data-dismiss="modal">Cancel</button>
                    </div>
                </div>
                <div class="form-group">
                <div class="alert alert-warning alert-dismissible" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                    </button>
                    <strong>Warning:</strong>: Please <a href="tel:+85212345678" class="alert-link">
                    call</a> us to reserve for more than six guests.
                </div>
                </div>
            </form>

Here is the file (mysqli_connect.php) for connecting to the database. This is working:

<?php
// This provides the information for accessing the database. 
// It also creates a connection to MySQL, 
// It selects the database, and sets the encoding.
// Set the database access information as constants:
DEFINE ('DB_USER', 'xxxx');
DEFINE ('DB_PASSWORD', 'xxxx');
DEFINE ('DB_HOST', 'xxxx');
DEFINE ('DB_NAME', 'xxxx');
// Make the connection:
$dbcon = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) 
OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
// Set the encoding...
mysqli_set_charset($dbcon, 'utf8');

The file connectivity-reserve.php is what I'm using to add the user into the database. Here is the code:

<?php
require ('mysqli_connect.php');

echo "yay";

if(isset($_POST['submit']))
{

$Customername = $_POST['Customername'];
$pwd  = $_POST['pwd'];
$q = "INSERT INTO users (user_id, cname, psword, ) VALUES (' ', '$Customername', '$pwd')";        

 $result = @mysqli_query ($dbcon, $q);

 if($result) 
    { 
        echo "YOUR REGISTRATION IS COMPLETED..."; 
    }
    else
    {
        echo "nah";
    }
}

?>

I'm able to connect to the database since the code echo "yay" is displayed on the browser. The issue is with the if(isset($_POST['submit'])) condition. I thought it should work since my button's type and name are 'submit' on the form:

<button type="submit" name ="submit" class="btn btn-primary">Reserve</button>

Help will be greatly appreciated.

Edit: Thanks guys! It was the , after psword. Also I know the code isn't secure. I'm just starting out with php so that isn't really a priority for me right now.

$q = "INSERT INTO users (user_id, cname, psword ) VALUES (' ', '$Customername', '$pwd')";     

Remove the comma from psword. Tested your code in my local db and is working just fine.

There is an error in your query:

Below statement:

$q = "INSERT INTO users (user_id, cname, psword, ) VALUES (' ', '$Customername', '$pwd')";    

should be:

$q = "INSERT INTO users (user_id, cname, psword) VALUES (' ', '$Customername', '$pwd')"; 

There was an additional comma which would fail the query and result in error.


Secondly, instead of checking if(isset($_POST['submit'])), you should check for Customername and pwd

if(isset($_POST['Customername']) && isset($_POST['pwd'])) {

Replace

<button type="submit" name ="submit" class="btn btn-primary">Reserve</button>

By

<input type="submit" name ="submit" class="btn btn-primary" value="Reserve">

Error in query

$q = "INSERT INTO users (user_id, cname, psword, ) VALUES (' ', '$Customername', '$pwd')";

comma after psword

INSERT INTO users (cname, psword, ) VALUES ('{$Customername}', '{$pwd}')

You Should remove user_id because its already auto i