0

这是我的表格:

<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 在表中返回零行。我似乎无法弄清楚为什么?提交数据后,如果表中已有任何数据,则不再将数据输入表中。任何帮助将不胜感激。

4

2 回答 2

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());
    }

}
于 2013-07-31T13:41:24.083 回答
-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?
}
于 2013-07-31T13:36:03.170 回答