I'm currently working on writing a form to a database, still a beginner. I attempted a form that i will show below but it seems to give me errors. If anyone could help me find out what is wrong with my PHP code then it would be great. Thanks in advance:
My form.php
<form method="post" action="db.php" name="OverrideForm" id="OverrideForm" autocomplete="on">
<fieldset>
<legend>Contact Details</legend>
<div>
<label for="name" accesskey="N">First Name</label>
<input name="name" type="text" id="name" required />
</div>
<div>
<label for="mname" accesskey="M">Middle Name</label>
<input name="mname" type="text" id="mname" required />
</div>
<div>
<label for="fname" accesskey="F">Last Name</label>
<input name="fname" type="text" id="fname" required />
</div>
<div>
<label for="sid" accesskey="i">Student ID</label>
<input name="sid" type="text" id="sid" size="10" required />
</div>
<div>
<label for="email" accesskey="E">Email</label>
<input name="email" type="email" id="email" pattern="^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$" required />
</div>
<div>
<label for="phone" accesskey="p">Phone Number</label>
<input name="phone" type="text" id="phone" size="8" required />
</div>
<div>
<label for="sc" accesskey="s">Scolarship</label>
<select name="sc" id="sc" required="required">
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
</fieldset>
<fieldset>
<legend>Subject Details</legend>
<div>
<label for="class" accesskey="c">Class</label>
<input name="class" type="text" id="class" size="50" required />
</div>
<div>
<label for="section" accesskey="o">Section</label>
<input name="section" type="text" id="section" size="1" required />
</div>
<div>
<label for="semester" accesskey="S">Semester</label>
<select name="semester" id="semester" required="required">
<option value="F15">Fall 2015</option>
<option value="S15">Summer 2015</option>
<option value="SP16">Spring 2016</option>
</select>
</div>
</fieldset>
<input type="submit" class="submit" id="submit" value="Submit" />
</form>
my db.php
<?php
$mysql_host = "localhost";
$mysql_username = "blahblah";
$mysql_password = "blahblah";
$mysql_database = "blahblah";
$mysqli = new Mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database) or die(mysql_error());
$prepare = $mysqli->prepare("INSERT INTO `Overrides`(`name`,`mname`,`fname`,`sid`,`email`,`phone`,`sc`,`class`,`section`,`semester`) VALUES ('$name','$mname','$fname','$sid','$email','$phone','$sc','$class','$section','$semester')");
$prepare->bind_param("ssssssssss", $_POST['name'], $_POST['mname'], $_POST['fname'], $_POST['sid'], $_POST['email'], $_POST['phone'], $_POST['sc'], $_POST['class'], $_POST['section'], $_POST['semester']);
$prepare->execute();
print_r($_POST)
?>
Error i'm getting is:
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in /home/aukwizcq/public_html/db.php on line 9
Array ( [name] => aaa [mname] => aaa [fname] => aaaa [sid] => 123456 [email] => fgfg@hotmail.com [phone] => 45454 [sc] => 1 [class] => Cpeg 340 [section] => 1 [semester] => S15 )
My db structure:
Name Type Collation Attributes Null Default Extra Action
1 name varchar(30) latin1_swedish_ci No None Change
2 mname varchar(30) latin1_swedish_ci No None Change
3 fname varchar(30) latin1_swedish_ci No None Change
4 sid varchar(11) latin1_swedish_ci No None Change Change
5 email varchar(50) latin1_swedish_ci No None Change
6 phone int(8) No None Change Change Drop Drop
7 sc bit(1) No None Change Change Drop Drop
8 class varchar(10) latin1_swedish_ci No None Change
9 section int(1) No None Change Change Drop Drop
10 semester varchar(11) latin1_swedish_ci No None Change