我想在html页面上更新一个名为user_setup的psql表。 我已经完成了这两个部分。首先是一个包含所有用户名的下拉列表。 一旦选择了用户名并按下提交,则该用户的ID,用户名,用户姓氏,Breaks1名称,Breaks1 Start和Breaks1完成将显示在该文本框中。 (这有效) 我现在想要的是能够编辑Breaks1名称,breaks1开始和breaks1完成数据并更新users_setup表。我创建了一个“更新详细信息”按钮来执行此操作。 当我按下该按钮时,在页面上出现以下错误:
Notice: Undefined variable: POST in /Users/davidjones/Sites/VCB V2/edit.php on line 71
Notice: Undefined variable: POST in /Users/davidjones/Sites/VCB V2/edit.php on line 71
Notice: Undefined variable: POST in /Users/davidjones/Sites/VCB V2/edit.php on line 71
Notice: Undefined variable: POST in /Users/davidjones/Sites/VCB V2/edit.php on line 72
Warning: pg_query(): Query failed: ERROR: syntax error at or near "," LINE 1: ...sers_setup SET breaks1_name = '', breaks1_start = , breaks1_... ^ in /Users/davidjones/Sites/VCB V2/edit.php on line 72
Update failed!!
我认为我的$ POST名称有误,但我尝试更改它们,但仍然收到错误。
我编写的代码如下:
<section>
<h2>Enter username</h2>
<ul>
<form name="display-username" action="edit.php" method="POST" >
<select name="username">
<?php
$conn = pg_connect("host=localhost dbname=vcbv3 user=postgres");
// get all the uid from the uid column in users
$result = pg_query($conn, "SELECT user_uid FROM users_setup");
if (!$result)
{
// error message
echo "An error occurred.\n";
exit;
}
// display on screen all uid data from users_setup in the dropdown
while ($row = pg_fetch_row($result))
{
echo "<option value='$row[0]'> $row[0] </option>\n";
}
?>
<!-- submit button to select username-->
<li><input type="submit" name="submit" /></li>
</select>
</form>
</ul>
</body>
</section>
<!-- submit button to select username-->
<?php
// find the username details on the users_setup table
$db = pg_connect("host=localhost dbname=vcbv3 user=postgres");
$result1 = pg_query($db, "SELECT * from users_setup WHERE user_uid= '$_POST[username]'");
$row = pg_fetch_assoc($result1);
if (isset($_POST['submit']))
{
// display the username details
echo "<ul>
<form name='update' action='edit.php' method='POST' >
<li>id:</li><li><input type='text' name='id_updated' value='$row[id]' /></li>
<li>First Name:</li><li><input type='text' name='user_first_name_updated' value='$row[user_first_name]' /></li>
<li>Last Name:</li><li><input type='text' name='user_last_name_updated' value='$row[user_last_name]' /></li>
<li>Breaks 1 Name:</li><li><input type='text' name='breaks1_name_updated' value='$row[breaks1_name]' /></li>
<li>Breaks 1 Start:</li><li><input type='time' name='breaks1_start_updated' value='$row[breaks1_start]' /></li>
<li>Breaks 1 Finish:</li><li><input type='time' name='breaks1_finish_updated' value='$row[breaks1_finish]' /></li>
</ul>";
}
?>
<li><input type="submit" name="Update" value="Update details"/></li>
<?php
if (isset($_POST['Update']))
{
// Update details on the users_setup table
$db = pg_connect("host=localhost dbname=vcbv3 user=postgres");
$result = pg_query($db, "UPDATE users_setup SET breaks1_name = '$POST[breaks1_name_updated]', breaks1_start = $POST[breaks1_start_updated], breaks1_finish = $POST[breaks1_finish_updated]
WHERE id = $POST[id_updated]");
if (!$result){
echo "Update failed!!";
}
else
{
echo "Update successfull;";
}
}
?>
有人可以帮助我,告诉我我做错了什么吗?