【发布时间】:2015-12-23 12:21:00
【问题描述】:
我正在尝试将表单中的数据发送到我的数据库中,但我似乎没有工作。表格字段是正确的。 s我有人能看出发生了什么问题吗?
表格:
<form class="myForm" role="form" action= "idea.php" method ="POST">
<h1 style="margin-top:50px; margin-bottom:30px; text-align:center; color:#0f4155;">Idea Form</h1>
<p1>Name:</p1>
<input type="text" class="form-control" name="name" placeholder="Name">
<p1>Originator:</p1>
<input type="text" class="form-control" name="originator" placeholder="Originator">
<p1>Alternative Contact</p1>
<input type="text" class="form-control" name="altcontact" placeholder="Alternative Contact">
<p1>Problem to Solve</p1>
<input type="text" class="form-control" name="problem" placeholder="Problem to Solve">
<p1>Description</p1>
<textarea class="form-control" rows="3" name="description" placeholder="Description"></textarea>
<p1>PO</p1>
<input type="text" class="form-control" name="po" placeholder="PO">
<p1>Archetypical Client</p1>
<input type="text" class="form-control" name="archclient" placeholder="Arcetypical Client">
<p1>Urgency</p1>
<input type="text" class="form-control" name="urgency" placeholder="Urgency" style="margin-bottom: 20px">
<p1>Technology/Platform</p1>
<input type="text" class="form-control" name="technology" placeholder="Technology/Platform">
<p1>Number of Sprints</p1>
<input type="number" class="form-control" name="sprints" placeholder="Number of Sprints">
<p1>Progress</p1>
<input type="text" class="form-control" name="progress" placeholder="Progress">
<input class="submit" name="submit" type="submit" value="Submit">
</form>
PHP:
if ($_SERVER["REQUEST_METHOD"] == "POST") { //if new idea is being added
$id = '';
$name = $_POST['name'];
$originator = $_POST['originator'];
$altcontact = $_POST['altcontact'];
$problem = $_POST['problem'];
$description = $_POST['description'];
$po = $_POST['po'];
$archclient = $_POST['archclient'];
$urgency = $_POST['urgency'];
$technology = $_POST['technology'];
$sprints = $_POST['sprints'];
$progress = $_POST['progress'];
$status = "submitted";
$strsq0 = "INSERT INTO idea (`id`,`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('" . $name . "," . $name . "," . $originator . "," . $altcontact . "," . $problem . ", " . $description . ", " . $po . "," . $archclient . ", " . $urgency . ", " . $technology . ", " . $sprints . ", " . $progress . ", " . $status . "');"; //query to insert new idea
if ($mysqli->query($strsq0)) {
echo "Insert success!";
} else {
echo "Cannot insert into the data table; check whether the table is created, or the database is active. " . mysqli_error();
}
}
【问题讨论】:
-
一方面,您没有在 SQL 查询的 VALUES 部分引用您的值,因此至少会失败。阅读准备好的陈述。 (您只需将值作为一个巨大的单列字符串)。
-
插入两次
VALUES ('" . $name . "," . $namename -
从插入到idea中删除
id -
请在您的应用程序中添加一些细节。在启动查询 sql 之前,您已连接到数据库?
-
请转义用户提供的值。或者绑定你的参数。否则你很容易被 SQL 注入。