php - Form writing to mysql database -


i'm working on writing form database, still beginner. attempted form show below seems give me errors. if me find out wrong php code great. 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 `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 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  

the syntax of prepared statement not right, variables should question marks. should this:

$prepare = $mysqli->prepare("insert `overrides`(`name`,`mname`,`fname`,`sid`,`email`,`phone`,`sc`,`class`,`section`,`semester`) values (?,?,?,?,?,?,?,?,?,?)"); 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -