2014-01-18 43 views
-3

好吧,所以我试图做一个简单的表单,其中用户点击一个按钮,通过输入表添加一段数据,然而无论何时我输入内容并提交如果没有通过数据库和想法为什么?数据没有插入(php到phpmyadmi数据库)

<?php 
     $connect = mysqli_connect('localhost','username','','password'); 
     if (!$connect){die("Can not connect:". mysqli_error());}  
     $db = new mysqli('localhost','uername','','password'); 

     if (isset($_POST['add_sd']) && $_POST['add_sd']){ 

      echo "<table cellpadding = 5px><tr><td><input type = text name = stdn_add placeholder= 'Type in The Student Number' /></td></tr> 
      <tr><td><input type = text name = fname_add placeholder = 'Type in their First Name'/></td><td><input type = text name = lname_add placeholder = 'Type in their Last Name'/></td></tr> 
      <tr><td><select name = feet><option></option><option value = 4 > 4 </option><option value = 5> 5 </option><option value = 6> 6 </option></select> Feet </td> 
      <td><select name = inches><option></option><option value = 0> 0 </option><option value = 1> 1 </option><option value = 2> 2 </option><option value = 3> 3 </option><option value = 4> 4 </option><option value = 5> 5 </option><option value = 6> 6 </option><option value = 7> 7 </option><option value = 8> 8 </option><option value = 9> 9 </option><option value = 10> 10 </option><option value = 11> 11 </option></select>Inches</td></tr> 
      <tr><td><input type = radio name = e_n value = 'Enable FullFit' /></td><td><input type = radio name = d_n value = 'Disable FullFit' /></td></tr> 
      <tr><input type = submit name = submit_edit value = 'Submit' /></tr> 
      </table>";  

      } 

      if (isset($_POST['e_n']) && $_POST['e_n']){$ff = "FF";} 

      else if(isset($_POST['d_n']) && $_POST['d_n']){$ff = " ";}  



       if (isset($_POST['stdn_add']) && $_POST['stdn_add'] && isset($_POST['fname_add']) && $_POST['fname_add'] && isset($_POST['lname_add']) && $_POST['lname_add'] && isset($_POST['feet']) && $_POST['feet'] && isset($_POST['inches']) && $_POST['inches'] && isset($_POST['e_n']) && $_POST['e_n'] && isset($_POST['d_n']) && $_POST['d_n'] && isset($_POST['submit'])){ 

        $insertinto_profile = $db -> query("INSERT INTO `profile` VALUES ('".$_POST['fname_add']."','".$_POST['lname_add']."','".$_POST['stdn_add']."',NULL,NULL,1234)"); 

        $insertinto_grad_specs = $db -> query("INSERT INTO `grad_specs` VALUES (NULL,'".$_POST['stdn_add']."','".$_POST['stdn_add']."','".$_POST['stdn_add']."','0','$ff','".$_POST['fname_add']."','".$_POST['lname_add']."')"); 

        $insertinto_info = $db -> query("INSERT INTO `excel_info` VALUES (NULL,'".$_POST['stdn_add']."','".$_POST['fname_add']."','".$_POST['lname_add']."','0','$ff')"); 

       } 
      ?> 
+3

-1没有调试工作,也没有努力保护您的代码。另外,感谢您的密码。 –

+0

语法lgtm,准备好的语句,编码风格指南和mysqli :: $ error是你的朋友 – worenga

回答

-1

插入语法是错误的:

解决方案:

You have to insert your column also along with your values. 

按照语法和在地方添加列名其中 “此处插入列名”是书面。

Follow the syntax: 

    INSERT INTO profile ("Insert the column names here") VALUES ("NULL,'".$_POST['stdn_add']."','".$_POST['stdn_add']."','".$_POST['stdn_add']."','0','$ff','".$_POST['fname_add']."','".$_POST['lname_add']."'") 
+2

Crikey ...在这里没有对SQL注入的免责声明或评论? – Aaron