RJMB
RJMB

Reputation: 43

MySQL not updating by index

This is a little strange, I'm probably missing something obvious here. One page outputs a table with checkboxes to display the data, then clicking on a button suspends (removes) the relevant rows whose boxes were checked. I'm trying to update a MySQL table by referencing the index. The dynamically generated table that sends data to the script in PHP looks like this:

<td class="controlpanelrows">
<input type="checkbox" name="suspend[]" value="'. $row {'index'} .'">
</td>

This correctly outputs the value of each checkbox as the index value of the row. Then I punt it off to a script via a form

<form action="suspend.php" method="post">
<table class="general" width="500"><tr>
.
.
.
</tr>
<? listRates(); ?>
</table>
<br><br>
<button class="mainButton" id="remove" value="remove" type="submit">Suspend</button>
</form>

And then the script updates the table so:

if (isset($_POST['suspend'])) {
foreach ($_POST['suspend'] as $suspend) {
mysql_query("UPDATE pay_week SET suspend='1' WHERE index='$suspend' ");
}
}

I've tested that it does receive the array, the query itself seems to be the problem. There's no easy way to address the data otherwise since the only unique element is the index, the script is receiving the data successfully, it's just not updating the table. The exact same script has worked perfectly for plenty of other datasets. The index field is set as INDEX.

Upvotes: 0

Views: 43

Answers (1)

user1477388
user1477388

Reputation: 21430

index is a reserved word. See https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Try

mysql_query("UPDATE pay_week SET suspend='1' WHERE `index` = '$suspend' ");

Upvotes: 2

Related Questions