Reputation: 35
Sorry this is an update on my last post which i deleted as it was not explained very well.
I am displaying all rows from a database by username and status. I want to add a button to each row that will change the status from 'open' to 'running'.
Here is my code so far but it changes all the rows with the particular username and i just need it to change only the row that the user presses the button for:
<?php
if (isset($_POST['running1'])) {
$getid = mysql_query("SELECT `id` FROM `event` WHERE `username` = '". $user_data['username'] ."'");
while($gatherid = mysql_fetch_assoc($getid)) {
$id = $gatherid['id'];
mysql_query("UPDATE `event` SET `status` = 'running' WHERE `id` = '". $id ."'");
}
} else {
mysql_error();
}
$event = mysql_query("SELECT * FROM `event` WHERE `status` = 'open' AND `username` = '". $user_data['username'] ."'");
while($get_event = mysql_fetch_assoc($event)) {
$venue = $get_event['venue'];
$title = $get_event['title'];
$status = $get_event['status'];
$available = $get_event['numbershare'];
$price = $get_event['individual_price'];
$id = $get_event['id'];
echo '
<tbody>
<tr>
<td>' . $venue . '</td>
<td>' . $title . '</td>
<td>' . $available . '</td>
<td>' . $price . '</td>
<td>' . $status . '</td>
<td><button class="btn-u">Link</button></td>
<td><form action="" method="post"><input type="submit" class="btn-u" name="running1"></form></td>
</tr>
</tbody>';
}
?>
Upvotes: 0
Views: 51
Reputation: 12772
1) add a hidden field in your form to track the id
<input type="hidden" value="' . $id . "'>
2) update your getid part to
$id = $_POST['id'];
3) execute the update
mysql_query("UPDATE `event` SET `status` = 'running' WHERE `id` = '". $id ."'") or throw Exception(mysql_error());
Upvotes: 1