By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,870 Members | 2,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,870 IT Pros & Developers. It's quick & easy.

unable to insert into db through php using xampp

P: 3
I am beginning web designer
I have project and i cannot found what is the problem
i connecte the html with php to inser data that submit to database
when i refresh the local host I could not find any inserted record!!
this is my html code
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  
  3. <html>
  4. <head>
  5.     <title>participator register</title>
  6.     <link rel=stylesheet type="text/css" href="style.css">
  7.     <script type= "text/javascript" src="buthandler.js"></script>
  8. </head>
  9.  
  10. <body bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0" background="img/background.jpg">
  11.  
  12. <table height="123" width="100%" cellpadding="0" cellspacing="0" border="0">
  13. <tr valign="top">
  14. <!----- insert logo below ------------------------------------------>
  15. <td><img src="img/ssp.png" width="200" height="123" border="0" alt=""></td>
  16. <!------------------------------------------------------------------>
  17. <td width="100%" background="img/topbg.jpg">&nbsp;</td>
  18. </tr>
  19. </table>
  20.  
  21. <table height="40" width="100%" cellpadding="0" cellspacing="0" border="0">
  22. <tr valign="top">
  23. <td width="100%" background="img/topbar.jpg">&nbsp;</td>
  24. </tr>
  25. </table>
  26.  
  27. <table width="100%" cellpadding="0" cellspacing="0" border="0">
  28. <tr valign="top">
  29.  
  30. <td width="201"><BR>
  31. <!----- menu, insert links below ------------------------------------------>
  32. &nbsp;&nbsp;&raquo;&nbsp;<a href="index.html">home</a><BR>
  33. <img src="img/menubar.jpg" width="201" height="11" border="0" alt=""><BR>
  34.  
  35. <!-------------------------------------------------------------------------->
  36. </td>
  37. <script type="text/javascript">
  38. function OnSubmitForm()
  39. {
  40. var tb1=document.getElementById("Fname").value;
  41.     var isNameCorrect = true;
  42.     for(var x=0;x<tb1.length;x++)
  43.      {
  44.        var c = tb1.charAt(x);
  45.  
  46.        if(c<65 | c>122 )
  47.        { 
  48.         isNameCorrect=false;
  49.         break;         
  50.        }
  51.  
  52.      }
  53.  
  54. var tb11=document.getElementById("Lname").value;
  55.     var isLNameCorrect = true;
  56.     for(var x=0;x<tb11.length;x++)
  57.      {
  58.        var c = tb11.charAt(x);
  59.  
  60.        if(c<65 | c>122 )
  61.        { 
  62.         isLNameCorrect=false;
  63.         break;         
  64.        }
  65.  
  66.      }
  67. var tb2=document.getElementById("pw").value;
  68.    var len = tb2.length;
  69. var tb3=document.getElementById("ID").value;
  70.      var isstartwith = true;
  71.      var istruelength = true;
  72.      var istruevalue = true;
  73.  
  74.        var c = tb3.charAt(0); 
  75.        var d = tb3.charAt(1);
  76.         if(c!="4" | d!="2")     
  77.           isstartwith = false;    
  78.         else
  79.          if(tb3.length!=9)    
  80.           istruelength =false;    
  81.         else
  82.          {
  83.             for(var e=0;e<tb3.length;e++)
  84.             {
  85.               var u = tb3.charAt(e);
  86.  
  87.               if(u=="1"|u=="2"|u=="3"|u=="4"|u=="5"|u=="6"|u=="7"|u=="8"|u=="9"|u=="0")
  88.               {
  89.  
  90.               }
  91.               else
  92.               {
  93.                 istruevalue=false;
  94.               break;
  95.               }
  96.             }
  97.          }         
  98.  
  99. var tb4=document.getElementById("mobile").value;
  100.      var ismobilestartwith = true;
  101.      var ismobiletruelength = true;
  102.      var ismobiletruevalue = true;
  103.  
  104.        var c = tb4.charAt(0); 
  105.        var d = tb4.charAt(1);
  106.         if(c!="0" | d!="5")     
  107.           ismobilestartwith = false;    
  108.         else
  109.          if(tb4.length!=10)    
  110.           ismobiletruelength =false;    
  111.         else
  112.          {
  113.             for(var e=0;e<tb4.length;e++)
  114.             {
  115.               var u = tb4.charAt(e);
  116.  
  117.               if(u=="1"|u=="2"|u=="3"|u=="4"|u=="5"|u=="6"|u=="7"|u=="8"|u=="9"|u=="0")
  118.               {
  119.  
  120.               }
  121.               else
  122.               {
  123.                 ismobiletruevalue=false;
  124.               break;
  125.               }
  126.             }
  127.          }         
  128. var tb5=document.getElementById("email").value;
  129.      var atsymbolIndex=tb5.indexOf("@");
  130.      var substr = tb5.substring(atsymbolIndex);  
  131. var tb6=document.getElementById("edulevel").value;
  132.     var iseduCorrect = true;
  133.     for(var x=0;x<tb6.length;x++)
  134.      {
  135.        var c = tb6.charAt(x);
  136.  
  137.        if(c<65 | c>122 )
  138.        { 
  139.         iseduCorrect=false;
  140.         break;         
  141.        }
  142.  
  143.      }
  144. var tb7=document.getElementById("major").value;
  145.      var ismajCorrect = true;
  146.     for(var x=0;x<tb7.length;x++)
  147.      {
  148.        var c = tb7.charAt(x);
  149.  
  150.        if(c<65 | c>122 )
  151.        { 
  152.         ismajCorrect=false;
  153.         break;         
  154.        }
  155.  
  156.      }
  157.  
  158. if(tb1.length==0|tb2.length==0|tb3.length==0|tb4.length==0|tb5.length==0|tb6.length==0|tb7.length==0|tb11.length==0)
  159. {
  160. alert("one or more filds is empty please fill all fields");
  161. }
  162.  
  163. else
  164. if(!isNameCorrect)
  165. alert("your first name should be written with english letter only");
  166. else
  167. if(!isLNameCorrect)
  168. alert("your last name should be written with english letter only");
  169. else
  170. if(len<6)
  171. alert("pass word should be at least six chracter");
  172. else
  173. if(!isstartwith)
  174. alert("Your ID should be start with 42");
  175. else
  176. if(!istruelength)
  177. alert("your ID should be nine digit exactly please re enter your ID");
  178. else
  179. if(!istruevalue)
  180. alert("your ID should be contain digit only");
  181. else
  182. if(!ismobilestartwith)
  183. alert("Your mobile number should be start with 05");
  184. else
  185. if(!ismobiletruelength)
  186. alert("your mobile number should be 10 digit exactly please re enter your ID");
  187. else
  188. if(!ismobiletruevalue)
  189. alert("your mobile number should be contain digit only");
  190. else
  191. if(atsymbolIndex<1 )
  192. alert("please enter your email");
  193. else
  194. if(substr!="@ksu.edu.sa")
  195.      alert("your entered email is incorrect. your email should be within \"@ksu.edu.sa\" domain please reEnter it");
  196. else
  197. if(!iseduCorrect)
  198. alert("the educational level should be written with english letter only");
  199. else
  200. if(!ismajCorrect)
  201. alert("the major should be written with english letter only");
  202. else
  203. {
  204. document.myform.action ="insreg.php";
  205. }
  206.  
  207. }
  208. </script>
  209. <td width="100%">
  210. <form name="myform" onsubmit="return OnSubmitForm();" method="post">
  211. <p>  </br> </p>
  212.   <p>
  213.   <font size="5" color="#1c436c">&nbsp;&nbsp;&nbsp;&nbsp; Regiteration Form</font>
  214.   </P>
  215.   </br>
  216.   <table>
  217.   <tr>
  218.   <td>
  219.  <label> &nbsp;&nbsp;&nbsp;&nbsp;first name in english 
  220.   </td>
  221.   <td>
  222.   <input type="text" id="Fname" name="Fname"></label>
  223.   </td>
  224.   </tr>
  225.     <tr>
  226.   <td>
  227.  <label> &nbsp;&nbsp;&nbsp;&nbsp;last name in english 
  228.   </td>
  229.   <td>
  230.   <input type="text" id="Lname" name="Lname"></label>
  231.   </td>
  232.   </tr>
  233.    <tr>
  234.   <td>
  235.  <label> &nbsp;&nbsp;&nbsp;&nbsp;pass word 
  236.   </td>
  237.   <td>
  238.   <input type="text" id="pw" name="pw"></label>
  239.   </td>
  240.   </tr> <tr>
  241.   <td>
  242.  <label> &nbsp;&nbsp;&nbsp;&nbsp;ID number 
  243.   </td>
  244.   <td>
  245.   <input type="text" id="ID" name="ID" value="42"></label>
  246.   </td>
  247.   </tr> <tr>
  248.   <td>
  249.  <label> &nbsp;&nbsp;&nbsp;&nbsp;mobile number
  250.   </td>
  251.   <td>
  252.   <input type="text" id="mobile" name="mobile" value="05"></label>
  253.   </td>
  254.   </tr> <tr>
  255.   <td>
  256.  <label> &nbsp;&nbsp;&nbsp;&nbsp;email address 
  257.   </td>
  258.   <td>
  259.   <input type="text" id="email" name="email" value="@ksu.edu.sa"></label>
  260.   </td>
  261.   </tr> <tr>
  262.   <td>
  263.  <label> &nbsp;&nbsp;&nbsp;&nbsp;educational level 
  264.   </td>
  265.   <td>
  266.   <input type="text" id="edulevel" name="edulevel"></label>
  267.   </td>
  268.   </tr> <tr>
  269.   <td>
  270.  <label> &nbsp;&nbsp;&nbsp;&nbsp;major 
  271.   </td>
  272.   <td>
  273.   <input type="text" id="major" name="major"></label>
  274.   </td>
  275.   </tr>
  276.  
  277.  </table>
  278.  <p>
  279.    &nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="submit">
  280.    </p>
  281. </form>
  282. </td>
  283.  
  284. </tr>
  285. </table>
  286.  
  287. </body>
  288. </html>
  289.  
  290.  
this is insreg.php page
Expand|Select|Wrap|Line Numbers
  1. <html >
  2. <head>
  3. <title></title>
  4.  
  5. </head>
  6. <body>
  7.  
  8. <?php
  9.  
  10.   //connect to mySql
  11.   $user="root";
  12.   $pass="";
  13.   $db = mysql_connect("localhost",$user,$pass);
  14.   if(!$db)
  15.     exit("error-could not connect to MySQL");
  16.  
  17.   $dbselect = mysql_select_db("SSS");//will changed
  18.   if(!$dbselect)  
  19.     exit("error-could not select the ss db");
  20.  
  21. //extract values of fields
  22. $Fname = $_POST['Fname'];
  23. $Lname = $_POST['Lname'];
  24. $pw = $_POST['pw'];
  25. $ID = $_POST['ID'];
  26. $mobile = $_POST['mobile'];
  27. $email = $_POST['email'];
  28. $edulevel = $_POST['edulevel'];
  29. $major = $_POST['major'];
  30. $query = "insert into participator values ('$ID','$Fname','$Lname','$pw','$mobile','$email','$edulevel','$major')";
  31. $result=mysql_query($query);
  32. if(!$result)
  33. {
  34.   print "ERROR-the query could not be executed";
  35.   $error = mysql_error();
  36.   print "<p>".$error."</p>";
  37.   exit;
  38. }
  39.  
  40. ?>
  41. </body>
  42. </html>
  43.  
Nov 29 '11 #1
Share this Question
Share on Google+
4 Replies


P: 3
no somebody can answer me :(
Nov 30 '11 #2

omerbutt
100+
P: 638
hi sara
dont be sad :D here lok at the line number 30 on insreg.php
you are not specifying field name for the table just inserting values
here is the format for the insert query
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO YOUR_TABLE_NAME(FIELD_NAME_1,FIELD_NAME_2,FIELDS_NAME_3) 
  2. VALUES('VALUE1','VALUE2','VALUE3')
  3.  
regards,
Omer Aslam
Dec 1 '11 #3

P: 3
thank you Omar to reply me
I detect my error
I did not move my files into hdoc folder in the local host
your reply is may another reason if I did not order the values as ordering of the field in the relation
thanks another time :)
Dec 1 '11 #4

omerbutt
100+
P: 638
hi sara,
Glad to be of help , cheers , happy programming.
regards,
Omer Aslam
Dec 2 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.