2016-05-25 63 views
-1

它回显到其他页面但未发送到数据库。有一个PHP页面只是为了连接到数据库。所以我在这个php页面中断开了与数据库的连接,但是出现了很多错误。表单中的信息未发送到数据库

这是代码:

<?php 
    require 'login.php'; 

     $path = 'img/'; 
     if (isset($_POST['submit'])) { 
     // Grab the image from the POST array 
     $fn = isset($_POST['fname']) ? $_POST['fname'] : ''; 
     $ln = isset($_POST['lname']) ? $_POST['lname'] : ''; 
     $sex = isset($_POST['sex']) ? $_POST['sex'] : ''; 
     $city = isset($_POST['city']) ? $_POST['city'] : ''; 
     $em = isset($_POST['email']) ? $_POST['email'] : ''; 
     $pass = isset($_POST['pword']) ? $_POST['pword'] : ''; 
     $confirm = isset($_POST['cword']) ? $_POST['cword'] : ''; 

     //$gend = $_POST['gender']; not using now 
     $pic = $_FILES['pic']['name']; 
     if (!empty($fn) && !empty($ln) && !empty($pic)) { 

     // Move the file to the target upload folder 
     $target = $path.$pic;//create image source (src) 
     if (move_uploaded_file($_FILES['pic']['tmp_name'], $target)) { 


     // // Connect to the database 
     $dbase = mysqli_connect('localhost', 'root', '', 'flowers'); 
     //Write the data to the database 
     $my_query = "insert into members values ('$fn', '$ln', '$sex','$city','$em','$pass', '$pic');"; 
     mysqli_query($dbase, $my_query); 


     // Confirm success with the user 
     echo '<p>Thank you for registering with us!</p>'; 
     echo '<p><strong>Name:</strong> ' . $fn .' '.$ln .'<br />'; 
     echo '<img src="' . $path . $pic . '" alt="profile image" /></p>'; 
     echo '<p><a href="index.html">&lt;&lt; Return to home page</a></p>'; 
     } 
     } 
     } 

表单代码:

<div id="formControl"> 
       <form id="form" action="img_upload.php" method="post" onsubmit="return validateForm(); "enctype="multipart/form-data"> 
        <fieldset> 
         <legend>Personal Information</legend> 

         <label> First Name: </label> <br/> 
          <input type="text" id="fname" name="fname"/> <br/> 
          <span id="f_error"></span><br/><br/> 

         <label>Last Name </label><br/> 
          <input type="text" name="lname" id="lname"/><br/><br/> 
          <span id="l_error"></span><br/> 

         <label> Sex: </label><br/> 
          Male <input type="radio" id="msex" name="sex" value="Male"/> 
          Female <input type="radio" id="fsex" name="sex" value="female"/> <br/> <br/> <br/> 

         <label>City: </label> 
          <select>  
           <option value="" selected="selected" name="city" id="add">Select a City</option> 
           <option value="sando">San Fernando</option> 
           <option value="pos">Port of Spain</option> 
           <option value="chag">Chaguanas</option> 
           <option value="arima">Arima</option> 
           <option value="bella">Marabella.</option> 
           <option value="point">Point Fortin</option> 
           <option value="puna">Tunapuna</option> 
           <option value="scarborough">Scarborough</option> 

          </select> 
          <span id="ad_error"></span><br/><br/> 
         </fieldset> 

         <fieldset> 
         <legend>Register</legend> 

         <label>Email Address</label><br/> 
          <input type="text" id="email" name="email"/><br/><br/> 
          <span id="em_error"></span><br/><br/> 

         <label> Password: </label><br/> 
          <input type="password" id="pword" name="pword"/> <br/> <br/> 
          <span id="p_error"></span><br/><br/> 

         <label>Confirm Password: </label><br/> 
          <input type="password" id="cword" name="cword"/> <br/> <br/> 
          <span id="c_error"></span><br/> 

         <label>Profile Picture: </label><br/> 
         <input type="file" name="pic" id = "pic" /><br/> <br/> <br/> 

         <input type="submit" name="submit" value="Submit"/> 
         <input type="reset" value="Reset"/> 


        </fieldset> 

       </form> 

      </div> 
+0

张贴您的表单代码! – Saty

+0

是INSERT查询的DB列是否正确? – epynic

+0

yes插入符合数据库 –

回答

0

请检查$质数据库链接后连接到数据库。它检查错误代码后检测到 。 也可以回显你的SQL查询知道什么发送到数据库和评估,复制它,并直接在您的MySQL数据库执行

0

请确保您的表的列数与您所插入。

我注意到你没有使用$gend变量,但它可能是你的表中的一列。

自动递增字段将被设置为默认+1每个新条目。我测试了一个类似的查询,我遇到了以下错误:

#1136 - Column count doesn't match value count at row 1

相关问题