数据没有插入(php到phpmyadmin数据库)

时间:2014-01-18 22:58:03

标签: php mysql

好吧所以我尝试制作一个简单的表单,用户点击按钮通过输入表添加一段数据,但每当我在框中输入内容并提交时如果不进入数据库和想法为什么?

    <?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')");

                }
            ?>

1 个答案:

答案 0 :(得分:-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']."'")