我无法将数据存储到MySQL中

时间:2014-02-08 12:56:22

标签: php mysql database insert

所以我有这个表格。我想将数据存储到我的数据库中。但是,它不是,并且没有错误日志。我真的很感激帮助,因为它需要在2天内完成,而且我在过去一周内一直在努力。

<form enctype="multipart/form-data" action="preview.php" method="post" class="f">
                <p>

                <p>
                            <p><label for="name">Teacher's Name:</label>
                                <input type="text" style="font-family:Gloria Hallelujah" size="35" name="name" id="name" autofocus required></p>
                            <p><label for="name">Title:</label>
                                <input type="text" style="font-family:Gloria Hallelujah" size="35" name="title" id="title" autofocus required></p>  
                            <p><label for="done">Done By:</label>
                                <input type="text" style="font-family:Gloria Hallelujah" size="35" name="done" id="done" required></p>
                            <p><label for="no">Class:</label>
                                <input type="text" style="font-family:Gloria Hallelujah" size="15" name="class" id="no" required></p>
                            <p><label for="sch">School:</label>
                                <select name="sch">
                                    <option value="seg">School of Engineering (SEG)</option>
                                    <option value="sit">School of Information Technology (SIT)</option>
                                    <option value="sdn">School of Design (SDN)</option>
                                    <option value="sbm">School of Business Management (SBM)</option>
                                    <option value="shs">School of Health Sciences (SHS)</option>
                                    <option value="scl">School of Chemical & Life Sciences (SCL)</option>
                                    <option value="sidm">School of Interactive and Digital Media (SIDM)</option>
                                </select>

                                            <p><label for="msg">Show your Gratitude! :</label>
                            <textarea class="tarea" maxlength="3000" cols="38.5" rows="6" name="comments" placeholder="Enter Message here..." required></textarea>
                            <p class="limit">Char limit: 3000 chars.</p>
                        </p>

它会转到preview.php,它应该存储数据。

<?php
include "mysqli.connect.php";
include "fbmain.php";

$sql = "INSERT INTO table(teacherName, title, doneBy, studentClass, school, message)VALUES    ('$_POST[name]','$_POST[title]','$_POST[done]','$_POST[class]','$_POST[comments]') where     facebookId = '".$me['id']."'";

3 个答案:

答案 0 :(得分:0)

INSERT命令不需要WHERE子句。

P.S:您对SQL Injection持开放态度。

答案 1 :(得分:0)

('$_POST[name]','$_POST[title]','...

更改为:

('{$_POST[name]}','{$_POST[title]}','...

这更好
http://ir1.php.net/mysqli_query 并检查数据库并检查WHERE结构
您可以显示错误并通过在查询后放置此代码来修复它们

if (mysqli_connect_errno()) {
  echo mysqli_connect_error();
  exit();
}

答案 2 :(得分:0)

$ _ POST [name]与$ _POST ['name']不同,$ _POST [title]与$ _POST ['title']等不同。

而不是:

$sql = "INSERT INTO table(teacherName, title, doneBy, studentClass, school, message)VALUES    ('$_POST[name]','$_POST[title]','$_POST[done]','$_POST[class]','$_POST[comments]') where     facebookId = '".$me['id']."'";

$name = $_POST['name'];
$title = $_POST['title'];
$done = $_POST['done'];
$class = $_POST['class'];
$comments = $_POST['comments'];

$sql = "INSERT INTO table(teacherName, title, doneBy, studentClass, school, message)VALUES    ('{$name}','{$title}','{$done}','{$class}','{comments}') where     facebookId = '".$me['id']."'";

但上面只是让它发挥作用!

这不是推荐的方法。您应该使用参数化查询... http://forum.codecall.net/topic/44392-php-5-mysqli-prepared-statements/