我的html表单不会POST到mysql

时间:2016-06-23 12:47:34

标签: php html mysql post

您好,我的数据没有被放入我的MYSQL数据库。 此外,屏幕上或php错误页面中根本没有任何错误。 我的代码如下。

这是包含

中所有数据的数组
  $time_submit = date('d/m/Y h:i:s a', time());
            $submit_data = array(
                'time_submit'               => $time_submit,
                'time_event'                => $_POST['date'] . " " . $_POST['hr'] . ":" . $_POST['min'],
                'project_number'            => $_POST['project'],
                'event'                     => $_POST['event'],
                'happened'                  => $_POST['happened'],
                'about_it'                  => $_POST['about_it'],
                'reporter_name'             => $_POST['reporter'],
                'organisation'              => $_POST['organisation'],
                'trackside'                 => $_POST['trackside'],
                'event_location'            => $_POST['location'],
                'phone_number'              => $_POST['number'],
                'yes_rules'                 => $_POST['rules'],
                'life_rules'                => $_POST['life_rules'],
                'require_feedback'          => $_POST['feedback'],
                'reporter_email'            => $_POST['email'],
                'region'                    => $_POST['region'],
                'photo'                     => $file_path
                    );
                    submit_form($submit_data);

我有一个提交数据的功能

function submit_form($submit_data) {
    global $conn;
    array_walk($submit_data, 'array_sanitize');
    $fields = '`' . implode('`, `', array_keys($submit_data)) . '`';
    $data = '\'' . implode('\', \'', $submit_data) . '\'';

    mysqli_query($conn,"INSERT INTO tb_data($fields) VALUES($data)");

}

我已经回应了所有事情以确保一切正常,一切看起来都很好。

我的表格

<form id="closecall" action="<? echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
        <ul class="form">
            <li><label><i>* Fields marked with an asterix are required</i></label></li><br />
            <? echo output_errors($errors); ?>
            <li><label for="date"><i>* </i>Event Date and time:<i class="required" id="datepicker_info">Required</i></label></li>
            <li>
                <input id="datepicker" type="text" name="date" >
                &nbsp;
                <select name="hr" id="hr">
                    <option value="">Hr</option>
                    <option value="01">01</option>
                    <option value="02">02</option>
                    <option value="03">03</option>
                    <option value="04">04</option>
                    <option value="05">05</option>
                    <option value="06">06</option>
                    <option value="07">07</option>
                    <option value="08">08</option>
                    <option value="09">09</option>
                    <option value="10">10</option>
                    <option value="11">11</option>
                    <option value="12">12</option>
                    <option value="13">13</option>
                    <option value="14">14</option>
                    <option value="15">15</option>
                    <option value="16">16</option>
                    <option value="17">17</option>
                    <option value="18">18</option>
                    <option value="19">19</option>
                    <option value="20">20</option>
                    <option value="21">21</option>
                    <option value="22">22</option>
                    <option value="23">23</option>
                    <option value="00">00</option>
                </select>
                <select name="min" id="min">
                    <option value="">Min</option>
                    <option value="00">00</option>
                    <option value="01">01</option>
                    <option value="02">02</option>
                    <option value="03">03</option>
                    <option value="04">04</option>
                    <option value="05">05</option>
                    <option value="06">06</option>
                    <option value="07">07</option>
                    <option value="08">08</option>
                    <option value="09">09</option>
                    <option value="10">10</option>
                    <option value="11">11</option>
                    <option value="12">12</option>
                    <option value="13">13</option>
                    <option value="14">14</option>
                    <option value="15">15</option>
                    <option value="16">16</option>
                    <option value="17">17</option>
                    <option value="18">18</option>
                    <option value="19">19</option>
                    <option value="20">20</option>
                    <option value="21">21</option>
                    <option value="22">22</option>
                    <option value="23">23</option>
                    <option value="24">24</option>
                    <option value="25">25</option>
                    <option value="26">26</option>
                    <option value="27">27</option>
                    <option value="28">28</option>
                    <option value="29">29</option>
                    <option value="30">30</option>
                    <option value="31">31</option>
                    <option value="32">32</option>
                    <option value="33">33</option>
                    <option value="34">34</option>
                    <option value="35">35</option>
                    <option value="36">36</option>
                    <option value="37">37</option>
                    <option value="38">38</option>
                    <option value="39">39</option>
                    <option value="40">40</option>
                    <option value="41">41</option>
                    <option value="42">42</option>
                    <option value="43">43</option>
                    <option value="44">44</option>
                    <option value="45">45</option>
                    <option value="46">46</option>
                    <option value="47">47</option>
                    <option value="48">48</option>
                    <option value="49">49</option>
                    <option value="50">50</option>
                    <option value="51">51</option>
                    <option value="52">52</option>
                    <option value="53">53</option>
                    <option value="54">54</option>
                    <option value="55">55</option>
                    <option value="56">56</option>
                    <option value="57">57</option>
                    <option value="58">58</option>
                    <option value="59">59</option>
                </select>
            </li><br />
            <li><label for="Project"><i>* </i>Involved Project:<i class="required" id="project_info">Required</i></label></li>
            <li><input id="project" name="project" type="text"></li><br />
            <li><label for="Event"><i>* </i>Describe the Event:<i class="required" id="event_info">Required</i></label></li>
            <li><textarea class="textarea" id="event" name="event"></textarea></li><br />
            <li><label for="happened"><i>* </i>What Could Have Happened:<i class="required" id="happened_info">Required</i></label></li>
            <li><textarea class="textarea" id="happened" name="happened"></textarea></li><br />
            <li><label for="about_it"><i>* </i>What were you able to do about it:<i class="required" id="about_info">Required</i></label></li>
            <li><textarea class="textarea" id="about_it" name="about_it"></textarea></li><br />
            <li><label for="reported">Reported By:</label></li>
            <li><input id="reported" name="reporter" type="text"/></li><br />
            <li><label for="organisation"><i>* </i>Organisation:<i class="required" id="organisation_info">Required</i></label></li>
            <li><input id="organisation" name="organisation" type="text"></li><br />
            <li><label for="trackside"><i>* </i>Trackside or Non-Trackside:</label></li>
            <li>
                <input type="radio" name="trackside" value="Trackside"><span>Trackside</span>
                <input type="radio" name="trackside" value="Non-Trackside" checked><span>Non-Trackside including Civils and Aiports</span>
            </li><br />
            <li><label for="location">Other Location Info (Stand No./ELR/Mileage etc):</label></li>
            <li class="optional"><span>(If Known)</span></li>
            <li><input id="location" name="location" type="text"/></li><br />
            <li><label for="number">Reporters Mobile Number:</label></li>
            <li><input id="contact" name="number" type="text"/></li><br />
            <li><label for="rules"><i>* </i>Potential Breach of Life Saving Rules? (Not Applicable to Airports):</label></li>
            <li>
                <input type="radio" name="rules" class="rules" value="Yes" ><span>Yes</span>
                <input type="radio" name="rules" class="rules" value="No"checked><span>No</span>
            </li><br />

            <li class="liferules" style="display: none;"><label for="liferules"><i>* </i>Life Saving Rules (Not Applicable to Airports):<i class="required" id="rules_info">Required</i></label></li>
            <li class="liferules" style="display: none;">
                <select  name="life_rules" id="liferules">
                    <option value="">Please Select!</option>
                    <option value="Working with electricity">Working with electricity</option>
                    <option value="Working with electricity-test before touch">Working with electricity-test before touch</option>
                    <option value="Always obey the speed limit and wear a seat belt.">Always obey the speed limit and wear a seat belt.</option>
                    <option value="Never use a hand-held or hands-free phone, or programme any other mobile device, while driving.">Never use a hand-held or hands-free phone, or programme any other mobile device, while driving.</option>
                    <option value="Working at height-without a harness">Working at height-without a harness</option>
                    <option value="Equipment fit for intended purpose">Equipment fit for intended purpose</option>
                    <option value="Under the influence of Drugs or Alcohol">Under the influence of Drugs or Alcohol</option>
                    <option value="Wasn't trained for the job at hand">Wasn't trained for the job at hand</option>
                    <option value="Entered exclusion zone(Without permission)">Entered exclusion zone(Without permission)</option>
                    <option value="Plans and Permits Weren't in place before Job">Plans and Permits Weren't in place before Job</option>
                </select>
            </li><br />

            <li><label for="feedback"><i>* </i>Does the Reporter Require Close Call Feedback:</label></li>
            <li>
                <input type="radio"  name="feedback" class="feedback" value="Yes" ><span>Yes</span>
                <input type="radio"  name="feedback" class="feedback" value="No"  checked/><span>No</span>
            </li><br />
            <li class="email" style="display: none;"><label for="email"><i>* </i>Please enter your email address:<i class="required" id="feedback_info">Required</i></label></li>
            <li class="email" style="display: none;"><input id="feedback" type="email" name="email"></li><br />
            <li><label for="region"><i>* </i>Region:<i class="required" id="region_info">Required</i></label></li>
            <li>
                <select id="region" name="region">
                    <option value="">Please Select!</option>
                    <option value="Wales and Western">Wales and Western</option>
                    <option value="Central">Central</option>
                    <option value="Southern">Southern</option>
                    <option value="Airports">Airports</option>
                </select>
            </li><br />
            <li><label><i>* Max 5MB Photos and PDF's only </i>Do you want to upload a file:</label></li>
            <li>
                <input type="radio"  name="upload" value="Yes"><span>Yes</span>
                <input type="radio"  name="upload" value="No"  checked/><span>No</span>
            </li><br />
            <li style="display: none;" class="fileload"><label for="image">File Upload:</label></li><br />
            <li style="display: none;" class="fileload"><input id="file0" type="file" name="file1" ></li><br />
            <li style="display: none;" class="fileload"><input name="button" type="button" value="Upload More"></li><br />
            <li style="display: none;" class="fileshow"><input type="file" name="file2"></li>
            <li style="display: none;" class="fileshow"><input type="file" name="file3"></li>
            <li style="display: none;" class="fileshow"><input type="file" name="file4"></li>
            <li style="display: none;" class="fileshow"><input type="file" name="file5"></li><br />
            <li><i class="required" id="end_info">Please fill out required fields!</i></li>
            <li><input id="submit" type="submit" value="Submit" ></li>
            <li></li>

我知道我的工作方式是错误的,我会改变它。

由于

1 个答案:

答案 0 :(得分:0)

您应该使用mysqli_error检查MySQL错误

if (!mysql_query($conn, ...)) {
    echo mysqli_error($conn);
}