Hi I searched for another method of inserting records from php form to xampp. I come across this one: https://www.youtube.com/watch?v=aXcp7IYi41Q
I combined all the answers from my last question and changed my code to this:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/style.css">
<title>BOOTSTRAP</title>
</head>
<body>
<div class="inquiry col-md-6">
<h1>Inquire Now</h1>
<form method="post" action="insert.php" id="frmBox" onsubmit="return formSubmit();">
<div class="form-group">
<label for="InputName">Name*</label>
<input class="form-control" type="text" id="inputName" placeholder="Name" name="CustName">
</div>
<div class="form-group">
<label for="InputLocation">Location*</label>
<input class="form-control" type="text" id="inputLocation" placeholder="Location" name="Location">
</div>
<div class="form-group">
<label for="SelectDate">Date of Event*</label>
<select class="form-control" id="SelectMonth" name="Month">
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apr</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sept</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<select class="form-control" id="SelectDay" name="Day">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select class="form-control" id="selectYear" placeholder="Year" name="Year">
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
<option>2021</option>
<option>2022</option>
</select>
</div>
<div class="form-group">
<label for="InputNumber">Number of Guests*</label>
<input class="form-control" type="Number" id="inputNumber" placeholder="Number" name="Guests">
</div>
<div class="form-group">
<label for="InputContact">Contact Number*</label>
<input class="form-control" type="text" id="inputContact" placeholder="Contact Number" name="ContactNum">
</div>
<input class="btn btn-default" type="submit" value="submit" name="submit">
</form>
</div>
</div>
</div>
<!--SCRIPT-->
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
function formSubmit(){
$.ajax({
type:'POST',
url:'insert.php',
data:$('#frmBox').serialize(),
success:function(response){
$('#success').html(response);
}
});
var form=document.getElementById('frmBox').reset();
return false;
}
</script>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>
This one for the insert.php
?php
$servername="localhost";
$username="root";
$dbpassword="";
$dbname="catering";
$conn=mysqli_connect($servername,$username,$dbpassword,$dbname);
if(!$conn){
die("Could Not Connect:".mysqli_connect_error());
}
else{
$CustName=test_input($_POST['CustName']);
$Location=test_input($_POST['Location']);
$Month=test_input($_POST['Month']);
$Day=test_input($_POST['Day']);
$Year=test_input($_POST['Year']);
$Guests=test_input($_POST['Guests']);
$ContactNum=test_input($_POST['ContactNum']);
$sql="INSERT INTO inquiry(CustName,Location,Month,Day,Year,Guests,ContactNum)VALUES('$CustName','$Location','$Month','$Day','$Year','$Guests','$ContactNum')";
if(mysqli_query($conn,$sql)){
echo "Thank you for Inquiring";
}
else{
echo "Failed to Inquire. Please try again";
}
mysqli_close($conn);
}
function test_input($data){
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
}
?>
Now it's better than my previous code, I ran it on localhost, when i submit my test info, like Name, Location, Month, Day, Year, Guests and Contact Number, then I clicked submit right? The url does not change anymore, meaning its successfully connected to the database. But when I get to mySQL database, it produced this results:
PIC OF DATABASE As you guys can see, its all zeroes and it only appeared in Guests and ContactNum. First attempt at submitting, I got two results, then i tried it again many times. All zeroes and only appears on two columns. What do you guys think could be the problem here? Could it be a server error, setup error, installation error? Or a declaration error? Mismatch of names? What could i be missing? Please help. Thank you.
Heres my previous question for reference: Submission of PHP Form to XAMPP MySQL database