So, my lecturer gave me a PHP code (basically a register form) and told me to design it using css & html
Basically, I have already design the form in HTML & CSS . And already add the PHP code in it .Creating a database and tables . Done everything…
I have got one problem, When I run the form website, It seems that when I fill up the form and hit the submit button (thats where my problem is) Check back my cpanel> database > table> structure . It doesnt save the details that I have already fill up the form. Please Help Me !!!
I will show you my code…This is my HTML code
<!--//////FORM//////--><!--//////FORM //////--><!--/////FORM//////-->
<form action="<?php
echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<!-- PHP-->
<!-- General -->
<div class="form-group">
<h2 class="heading">Booking & contact</h2>
<div class="controls">
<input type="text" id="name" class="floatLabel" name="name" value="<?= $varName;
?>" />
<label for="name">Name</label>
</div>
<div class="controls">
<input type="text" id="email" class="floatLabel" name="email" value="<?= $varEmail;
?>" />
<label for="email">Email</label>
</div>
<div class="controls">
<input type="tel" id="phone" class="floatLabel" name="phone" value="<?= $varPhone;
?>" />
<label for="phone">Phone</label>
</div>
<div class="grid">
<div class="col-2-3">
<div class="controls">
<input type="text" id="street" class="floatLabel" name="street" value="<?= $varStreet;
?>" />
<label for="street">Street</label>
</div>
</div>
<div class="col-1-3">
<div class="controls">
<input type="number" id="street-number" class="floatLabel" name="number" value="<?= $varNumber;
?>" />
<label for="street-number">Number</label>
</div>
</div>
</div>
<div class="grid">
<div class="col-2-3">
<div class="controls">
<input type="text" id="city" class="floatLabel" name="city" value="<?= $varCity;
?>" />
<label for="city">City</label>
</div>
</div>
<div class="col-1-3">
<div class="controls">
<input type="text" id="post-code" class="floatLabel" name="post-code" value="<?= $varPostCode;
?>" />
<label for="post-code">Post Code</label>
</div>
</div>
</div>
<div class="controls">
<input type="text" id="country" class="floatLabel" name="country" value="<?= $varCountry;
?>" />
<label for="country">Country</label>
</div>
</div>
<!-- Details -->
<div class="form-group">
<h2 class="heading">Details</h2>
<div class="grid">
<div class="col-1-4 col-1-4-sm">
<div class="controls">
<input type="date" id="arrive" class="floatLabel" name="arrive" value="<?php
echo date('Y-m-d'); ?>">
<label for="arrive" class="label-date"><i class="fa fa-calendar"></i> Arrive</label>
</div>
</div>
</div>
<div class="grid">
<div class="col-1-3 col-1-3-sm">
<div class="controls"> <i class="fa fa-sort"></i>
<select class="floatLabel">
<option value="blank"></option>
<option value="1" <?php if ($varPeople === "Less than 5") echo ("selected=\"selected\""); ?>>Less than 5</option>
<option value="2" <?php if ($varPeople === "More than 5") echo ("selected=\"selected\""); ?>>More than 5</option>
<option value="3" <?php if ($varPeople === "More than 10") echo ("selected=\"selected\""); ?>>More than 10</option>
</select>
<label for="fruit"><i class="fa fa-male"></i> People</label>
</div>
</div>
<div class="col-1-3 col-1-3-sm">
<div class="controls"> <i class="fa fa-sort"></i>
<select class="floatLabel">
<option value="blank"></option>
<option value="deluxe" <?php if ($varTables === "Indoor") echo ("selected=\"selected\""); ?>>Indoor</option>
<option value="Zuri-zimmer" <?php if ($varTables === "Outdoor") echo ("selected=\"selected\""); ?>>Outdoor</option>
<option value="Zuri-zimmer" <?php if ($varTables === "VIP Room") echo ("selected=\"selected\""); ?>>VIP Room</option>
</select>
<label for="fruit">Tables</label>
</div>
</div>
<div class="col-1-3 col-1-3-sm">
<div class="controls"> <i class="fa fa-sort"></i>
<select class="floatLabel">
<option value="single-bed" <?php if ($varTime === "Breakfast") echo ("selected=\"selected\""); ?>>Breakfast</option>
<option value="double-bed" <?php if ($varTime === "Lunch") echo ("selected=\"selected\""); ?>>Lunch</option>
<!-- Add "selected >Lunch" when not using php code -->
<option value="double-bed" <?php if ($varTime === "Dinner") echo ("selected=\"selected\""); ?>>Dinner</option>
</select>
<label for="fruit">Time</label>
</div>
</div>
</div>
<div class="grid">
<p class="info-text">Please describe your needs e.g. Annual Dinner, Party</p>
<br>
<div class="controls">
<textarea name="comments" class="floatLabel" id="comments"><?= $varComment;
?>
</textarea>
<label for="comments">Comments</label>
</div>
<button type="submit" value="Submit" class="col-1-4">Submit</button>
</div>
</div>
<!-- /.form-group -->
</form>
THIS IS MY PHP CODE :
<?php
if($_POST['formSubmit'] === "Submit")
{
$errorMessage = "";
if(empty($_POST['formName']))
{
$errorMessage .= "<li> You forgot to enter your name! </li>";
}
if(empty($_POST['formEmail']))
{
$errorMessage .= "<li>You forgot to enter a IC! </li>";
}
//Doesnt Have List
$varName = $_POST['name'];
$varEmail = $_POST['email'];
$varPhone = $_POST['phone'];
$varStreet = $_POST['street'];
$varNumber = $_POST['street-number'];
$varCity = $_POST['city'];
$varPostCode = $_POST['post-code'];
$varCountry = $_POST['country'];
//Have List
$varPeople = $_POST['arrive'];
$varTables = $_POST['tables'];
$varTime = $_POST['time'];
$varComment = $_POST['comments'];
if(empty($errorMessage))
{
$db = mysql_connect ('sql***.byethost*.com','b*_*******','password');
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db('b*_*******_reservation',$db);
$sql = "INSERT INTO form2 (Name, Email, Phone, Street, Number, City, PostCode, Country, People, Tables, Time, Comment) VALUES (".
//Doesnt Have List
PrepSQL($varName) . ", ".
PrepSQL($varEmail) . ", ".
PrepSQL($varPhone) . ", ".
PrepSQL($varStreet) . ", ".
PrepSQL($varNumber) . ", ".
PrepSQL($varCity) . ", ".
PrepSQL($varPostCode) . ", ".
PrepSQL($varCountry) . ", ".
//Have List
PrepSQL($varPeople) . ", ".
PrepSQL($varTables) . ", ".
PrepSQL($varTime) . ", ".
PrepSQL($varComment) . ") ";
mysql_query($sql);
header('Location:thankyou.html');
exit();
}
}
//function:PrepSQL()
//use stripslashes and mysql_real_escape_string PHP functions
//tosanitize a string for use in an SQL query
//
//also puts single quotes around the string
//
function PrepSQL($value)
{
//Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
//Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
?>
There must be some mistake that I did wrong , If you can help me … I would thanks you a million times
You are welcome to check the demohttp://teikfai.byethost8.com/Table/form2.php?ckattempt=1