这是我的表格:
<div id="HomeAgenda">
<div id="HomeAgendaTitle">Agenda</div>
<div id="HomeAgendaCreate">
<form method="post" action="#">
<input type="text" name="HomeAgendaCreateTitle" id="HomeAgendaCreateTitle" placeholder="Subject" /><br>
<input type="text" name="HomeAgendaCreateLocation" id="HomeAgendaCreateLocation" placeholder="Location" /><br>
<input type="text" name="HomeAgendaCreateDate" id="HomeAgendaCreateDate" placeholder="Date" />
<input type="text" name="HomeAgendaCreateTime" id="HomeAgendaCreateTime" placeholder="Time" /><br>
<input type="text" name="HomeAgendaCreateNotes" id="HomeAgendaCreateNotes" placeholder="Notes" />
<input type="submit" name="HomeAgendaCreateSubmit" id="HomeAgendaCreateSubmit" value="Save" />
</form>
</div>
</div>
这是我的php:
<?php
$SetAgendaAppointment = @$_POST['HomeAgendaCreateSubmit'];
$SetAgendaTitle = @$_POST['HomeAgendaCreateTitle'];
$SetAgendaLocation = @$_POST['HomeAgendaCreateLocation'];
$SetAgendaDate = @$_POST['HomeAgendaCreateDate'];
$SetAgendaTime = @$_POST['HomeAgendaCreateTime'];
$SetAgendaNotes = @$_POST['HomeAgendaCreateNotes'];
if($SetAgendaAppointment) {
mysql_query("INSERT INTO agenda VALUES('$SetAgendaTitle','$SetAgendaLocation','$SetAgendaDate','$SetAgendaTime','$SetAgendaNotes','$user_id')");
}
?>
这是我的数据库连接代码:
<?php
mysql_connect("localhost","root","250317") or die(mysql_error());
mysql_select_db("bakpakk");
?>
在我从表单提交信息后的页面上,没有任何反应。当我检查议程表时,没有提交任何内容,phpmyadmin在表中返回零行。我似乎无法弄清楚为什么?提交数据后,如果表格中已有任何数据,则表格中不会输入更多数据。我们非常感谢您提供帮助。
答案 0 :(得分:0)
添加一些错误捕获代码,以便查看查询是否出错。
if($SetAgendaAppointment) {
$SQL = "INSERT INTO agenda VALUES('$SetAgendaTitle','$SetAgendaLocation','$SetAgendaDate','$SetAgendaTime','$SetAgendaNotes','$user_id')";
//ensure your creating the proper statement
var_dump($SQL);
$result = mysql_query($SQL);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
}
答案 1 :(得分:-1)
//ensure you're getting your variables
vardump($_POST);
if($SetAgendaAppointment) {
$SQL = "INSERT INTO agenda VALUES('$SetAgendaTitle','$SetAgendaLocation','$SetAgendaDate','$SetAgendaTime','$SetAgendaNotes','$user_id')";
//ensure you're creating the proper statement
var_dump($SQL);
mysql_query($SQL); // what are you doing with this? you're just running it and not saving it to a var?
}