View Full Version : update/delete from database problem

01-12-2006, 04:59 PM
$ud_id= $_POST['ud_id'];

echo "<center><table>";

if ($user) {
if($result = mysql_query('SELECT * FROM '.$user.' '))
while ($row=mysql_fetch_assoc($result)) {
echo "<center><table>";
echo '<form action=" ' . $PHP_SELF .' " method="POST">
<tr><td>Comments:</td><td><input type="text" name="ud_comments" value="' . $row['comments']. '"></td></tr>
<tr><td> </td><td><input type="submit" name="delete" value="X"> <input type="Submit" name="submit" value="Update"></td></tr>
echo "</table></center><br>";

if (isset($_POST['submit'])) {
mysql_query('UPDATE '.$user.' SET `comments`="' . $_POST['ud_comments] . '" WHERE `ud_id`="' . $_POST['ud_id'] .'"') or die (mysql_error());
echo 'Record Updated.';
echo '<script>window.location="' . $PHP_SELF . '";</script>';

if (isset($_POST['delete'])) {
mysql_query('DELETE FROM '.$user.' WHERE `id`="'.$_POST['ud_id'] .'"') or die (mysql_error());
echo '<script>window.location="updates.php";</script>';


mysql_close(); }}

echo "<center>Must be logged in!</center>";}


whats the problem?

the submit bit works because i get the "test" message

when i press delete or update submission buttons it just refreshes the page as desired but the new data is not enter or delete and remains unchanged....

and i get no errors... its connecting to data properly becasue i can add comments using

$query="INSERT INTO ".$user." VALUES ('','$comments')";
mysql_close();in another file
i had it working and didnt and now it doesnt work i dont think i changed anything.... :(

01-12-2006, 09:10 PM
you are not passing the "ud_id" in your form so consequently your queries do not know which record to update/delete. you need to pass the "ud_id" either via GET on the URL or via hidden form fields.