PHP/HTML Storing data to database. What's wrong in my coding? -


i'm creating simple database don't know why not working. when click 'submit' button doesn't create table , doesn't store data in data base.

there no error report showing don't know whats wrong.

here code.

<?php // controlled page require_once('pdsaccontrolled.php'); //includes db connection  $surnamex = $_post["surname"]; $firstnamex = $_post["firstname"]; $middlenamex = $_post["middlename"]; $nameextensionx = $_post["nameextension"]; $bdatex = $_post["bdate"]; $bplacex = $_post["bplace"]; $sexx = $_post["sex"]; $civstatx = $_post["civstat"]; $citizenshipx = $_post["citizenship"]; $heightx = $_post["height"]; $weightx = $_post["weight"]; $bloodtypetx = $_post["bloodtype"]; $gsisnox = $_post["gsisno"]; $pagibignox = $_post["pagibigno"]; $philhealthnox = $_post["philhealthno"]; $sssx = $_post["sssno"]; $resaddx = $_post["resadd"]; $zipcodex = $_post["zipcode"]; $telnox = $_post["telno"]; $emailaddx = $_post["emailadd"]; $cellnox = $_post["cellno"]; $agencynox = $_post["agencyno"]; $tin = $_post["tin"];   $uid = mysql_real_escape_string($uid);  if($_post['submitbutton'] == "submit") {  $sql = "create table $uid         ( _key int not null auto_increment         , surname  text(50) not null default '?'         , firstname  text(50) not null default '?'         , middlename  text(50) not null default '?'         , nameextension  text(50) not null default '?'         , bdate  date not null default '?'         , bplace  text(200) not null default '?'         , sex  text not null default '?'         , civstat  text not null default '?'         , citizenship  text(50) not null default '?'         , height  int(10) not null default '?'         , weight  int(10) not null default '?'         , bloodtype  text(50) not null default '?'         , gsisno  text(50) not null default '?'         , pagibigno  text(50) not null default '?'         , philhealthno  text(50) not null default '?'         , sssno  text(50) not null default '?'         , resadd  text(500) not null default '?'         , zipcode  text(50) not null default '?'         , telno  int(20) not null default '?'         , emailadd  text(50) not null default '?'         , cellno  int(20) not null default '?'         , agencyno  text(50) not null default '?'         , tin  text(50) not null default '?'         , primary key (_key))";             $query="insert $uid(surname,firstname,middlename,nameextension,bdate,bplace,sex,civstat,citizenship,height,weight,bloodtype,gsisno,pagibigno,philhealthno,sssno,resadd,zipcode,telno,emailadd,cellno,agencyno,tin)values('$surnamex','$firstnamex','$nameextensionx','$bdatex','$bplacex','$sexx','$civstatx','$citizenshipx','$heightx','$weightx','$bloodtypex','$gsisnox','$pagibignox','$philhealthnox','$sssnox','$resaddx','$zipcodex','$telnox','$emailaddx','$cellnox','$agencynox','$tinx')";          mysql_query($query) or die (mysql_error());         echo "the user $uid has been succesfully registered.";    } ?>            <!doctype html> <html> <head> <meta charset="utf-8"> <title> online pds | personal info </title> <script src="pdsjavascript.js"></script>  <link rel="stylesheet" type="text/css" href="pdscss.css"> </head>   <body>   <center> <form method='post' action='pdsformpersonalinfo.php'> <table border=1 cols='3' width='500px'> <tr><td colspan='3' id='titlehead' class='head'>i. personal information</td></tr> <tr><td><font color='red' size='3'>*</font>surname</td><td>:</td><td><input type='text' name='surname' size='30' maxlength='50' required='required' class=''></td></tr> <tr><td><font color='red' size='3'>*</font>first name</td><td>:</td><td><input type='text' name='firstname' size='30' maxlength='50' required='required'></td></tr> <tr><td><font color='red' size='3'>*</font>middle name</td><td>:</td><td><input type='text' name='middlename' size='30' maxlength='50' required='required'></td></tr> <tr><td>name extension</td><td>:</td><td><input type='text' name='nameextension' size='30' maxlength='50'></td></tr> <tr><td><font color='red' size='3'>*</font>date of birth(mm/dd/yyyy)</td><td>:</td><td><input type='date' name='bdate' required='required'></td></tr> <tr><td><font color='red' size='3'>*</font>birthplace</td><td>:</td><td><input type='text' name='bplace' size='30' maxlength='200' required='required'></td></tr> <tr><td><font color='red' size='3'>*</font>sex</td><td>:</td><td>male <input type='radio' name='sex' value='male' required='required'> female <input type='radio' name='sex' value='female' required='required'></td></tr> <tr><td><font color='red' size='3'>*</font>civil status</td><td>:</td><td><input type='radio' name='civstat' value='single' required='required'  onclick='document.getelementbyid("civstaton").setattribute("disabled","disabled");document.getelementbyid("civstaton").value = "";'> single                              <br><input type='radio' name='civstat' value='married' required='required'  onclick='document.getelementbyid("civstaton").setattribute("disabled","disabled");document.getelementbyid("civstaton").value = "";'> married                              <br><input type='radio' name='civstat' value='annuled' required='required'  onclick='document.getelementbyid("civstaton").setattribute("disabled","disabled");document.getelementbyid("civstaton").value = "";'> annuled                              <br><input type='radio' name='civstat' value='widowed' required='required'  onclick='document.getelementbyid("civstaton").setattribute("disabled","disabled");document.getelementbyid("civstaton").value = "";'> widowed                              <br><input type='radio' name='civstat' value='seperated' required='required' onclick='document.getelementbyid("civstaton").setattribute("disabled","disabled");document.getelementbyid("civstaton").value = "";'> seperated                              <br><input type='radio' name='civstat' required='required' onclick='document.getelementbyid("civstaton").removeattribute("disabled");'> others,                              please specify here<br><input type='text' name='civstat' size='30' id='civstaton' disabled required='required'></td>                             </tr> <tr><td><font color='red' size='3'>*</font>citizenship</td><td>:</td><td><input type='text' name='citizenship' size='30' maxlength='50' required='required'></td></tr> <tr><td><font color='red' size='3'>*</font>height (meter)</td><td>:</td><td><input type='number' name='height' size='30' maxlength='10' min='0' max='18' step='0.1' required='required'></td></tr> <tr><td><font color='red' size='3'>*</font>weight (kilogram)</td><td>:</td><td><input type='number' name='weight' size='30' maxlength='10' min='0' max='300' step='0.1' required='required'></td></tr> <tr><td><font color='red' size='3'>*</font>blood type</td><td>:</td><td><input type='text' name='bloodtype' size='30' maxlength='50' required='required'></td></tr> <tr><td>gsis id number</td><td>:</td><td><input type='text' name='gsisno' size='30' maxlength='50'></td></tr> <tr><td>pag-ibig id number</td><td>:</td><td><input type='text' name='pagibigno' size='30' maxlength='50'></td></tr> <tr><td>philhealth number</td><td>:</td><td><input type='text' name='philhealthno' size='30' maxlength='50'></td></tr> <tr><td>sss number</td><td>:</td><td><input type='text' name='sssno' size='30' maxlength='50'></td></tr> <tr><td><font color='red' size='3'>*</font>residential address</td><td>:</td><td><textarea name='resadd' style='width:215px;height:100px;' maxlength='500' wrap='physical' style='resize:none' required='required'></textarea></td></tr> <tr><td><font color='red' size='3'>*</font>zip code</td><td>:</td><td><input type='text' name='zipcode' size='30' maxlength='50' required='required'></td></tr> <tr><td>telephone number</td><td>:</td><td><input type='tel' name='telno' size='30' maxlength='50'></td></tr> <tr><td>e-mail address(if any)</td><td>:</td><td><input type='email' name='emailadd' size='30' maxlength='50'></td></tr> <tr><td>cellphone number(if any)</td><td>:</td><td><input type='tel' name='cellno' size='30' maxlength='50'></td></tr> <tr><td>agency employee number</td><td>:</td><td><input type='text' name='agencyno' size='30' maxlength='50'></td></tr> <tr><td>tin</td><td>:</td><td><input type='text' name='tin' size='30' maxlength='50'></td></tr> <tr><td colspan='3'><font color='red' size='5'>*</font>required fields<center>    <input type='submit' name='submitbutton' value='next'>&nbsp&nbsp&nbsp&nbsp<input   type='reset' value='reset'></center></td></tr> </table> </form> </center>  </body>   </html> 

it appears you're creating separate table every user, really bad idea, in every case.

specifically, isn't working because -- although you're creating sql create table, never use it. you're skipping straight trying insert row table doesn't exist.

someone jump in enough , tell use more-modern php mysql interfaces (mysqli or pdo). they're right, suggest better logic setup have:

$surnamex = mysql_real_escape_string($_post["surname"]); $firstnamex = mysql_real_escape_string($_post["firstname"]); $middlenamex = mysql_real_escape_string($_post["middlename"]); $nameextensionx = mysql_real_escape_string($_post["nameextension"]); $bdatex = mysql_real_escape_string($_post["bdate"]); $bplacex = mysql_real_escape_string($_post["bplace"]); $sexx = mysql_real_escape_string($_post["sex"]); $civstatx = mysql_real_escape_string($_post["civstat"]); $citizenshipx = mysql_real_escape_string($_post["citizenship"]); $heightx = mysql_real_escape_string($_post["height"]); $weightx = mysql_real_escape_string($_post["weight"]); $bloodtypetx = mysql_real_escape_string($_post["bloodtype"]); $gsisnox = mysql_real_escape_string($_post["gsisno"]); $pagibignox = mysql_real_escape_string($_post["pagibigno"]); $philhealthnox = mysql_real_escape_string($_post["philhealthno"]); $sssx = mysql_real_escape_string($_post["sssno"]); $resaddx = mysql_real_escape_string($_post["resadd"]); $zipcodex = mysql_real_escape_string($_post["zipcode"]); $telnox = mysql_real_escape_string($_post["telno"]); $emailaddx = mysql_real_escape_string($_post["emailadd"]); $cellnox = mysql_real_escape_string($_post["cellno"]); $agencynox = mysql_real_escape_string($_post["agencyno"]); $tin = mysql_real_escape_string($_post["tin"]);  $uid = mysql_real_escape_string($uid);  if($_post['submitbutton'] == "submit") {   // single "users" table, 1 row per user, including uid    $sql = "create table if not exist users         ( _key int not null auto_increment,         uid text(50) not null         , surname  text(50) not null default '?'         , firstname  text(50) not null default '?'         , middlename  text(50) not null default '?'         , nameextension  text(50) not null default '?'         , bdate  date not null default '?'         , bplace  text(200) not null default '?'         , sex  text not null default '?'         , civstat  text not null default '?'         , citizenship  text(50) not null default '?'         , height  int(10) not null default '?'         , weight  int(10) not null default '?'         , bloodtype  text(50) not null default '?'         , gsisno  text(50) not null default '?'         , pagibigno  text(50) not null default '?'         , philhealthno  text(50) not null default '?'         , sssno  text(50) not null default '?'         , resadd  text(500) not null default '?'         , zipcode  text(50) not null default '?'         , telno  int(20) not null default '?'         , emailadd  text(50) not null default '?'         , cellno  int(20) not null default '?'         , agencyno  text(50) not null default '?'         , tin  text(50) not null default '?'         , primary key (_key))";          mysql_query($sql) or die (mysql_error());          $query="insert users (uid, surname,firstname,middlename,nameextension,bdate,bplace,sex,civstat,citizenship,height,weight,bloodtype,gsisno,pagibigno,philhealthno,sssno,resadd,zipcode,telno,emailadd,cellno,agencyno,tin)values('$uid',$surnamex','$firstnamex','$nameextensionx','$bdatex','$bplacex','$sexx','$civstatx','$citizenshipx','$heightx','$weightx','$bloodtypex','$gsisnox','$pagibignox','$philhealthnox','$sssnox','$resaddx','$zipcodex','$telnox','$emailaddx','$cellnox','$agencynox','$tinx')";          mysql_query($query) or die (mysql_error());         echo "the user $uid has been succesfully registered.";  } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -