表单中的信息不会发送到数据库

时间:2016-05-25 06:35:27

标签: php

它回显到其他页面但没有发送到数据库。有一个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>

2 个答案:

答案 0 :(得分:0)

连接数据库后请检查$ dbase链接。 之后检查错误代码。 你也可以回复你的sql Query来了解发送到数据库的内容并评估它,将其复制并直接在你的mysql数据库中执行

答案 1 :(得分:0)

确保表格的列数与您要插入的值的数量相匹配。

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

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

  

#1136 - 列数与第1行的值计数不匹配