I am wanting to update a psql table called user_setup, off a html page. I have done this 2 parts. First there is a drop list which has all the user names. Once a username is selected and submit is pressed the ID, User First name, User Last name, Breaks1 name, Breaks1 Start & Breaks1 finish for that user is displayed in there text boxes. (This works) What i want now is to able to edit the Breaks1 name, breaks1 start and breaks1 finish data and update the users_setup table.I have created a button 'Update details' to do this. When pressed though i am geeting the following errors on the page :
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!!
I presume i have got the $POST names wrong but i have tried changing them but still get the errors.
The code i have written is as follows :
<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.
";
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>
";
}
?>
<!-- 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;";
}
}
?>
Can anyone help me and show me what i have done wrong please?