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">×</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.