I randomly get a row from a mysql-database using php (ugly random, I know). I then want to update a specific field in the row that I get (using form or POST), but I can’t seem to get it to work. I have tried to create an alias for the specific ID to use in the form-post, but that failed.
$query_Recordset1 = "SELECT id, username, message, ttime, field1, field2 FROM table WHERE done = 0 ORDER BY RAND() LIMIT 1";
Then I want to update field1 if a specific submit-button is pressed, the important thing is that it writes to the random row (specific ID) that is fetched.
<?php
if($submit)
{ mysql_select_db("database", $connection);
$sql = "UPDATE table SET field1 = field1 +1 WHERE id = '???')";
$result = mysql_query($sql);
}
?>
<form method="post" action="">
<input type="submit" name="submit" value="submit">
</form>
Any takes on my problem? Thanks!
You are doing it right
That’s just an example.
In you example, you would probably want to create a hidden field that contains the id
Then on your receiving page