Jump to content

mysql update database errors


DannyM

Recommended Posts

Hello all

 

I've encountered an error with my PHP update code. Here it is:

 

<?php


$con=mysql_connect(xxxxxxxxx);
if(!$con){
die("Cannot establish a connection.");
}
$db=mysql_select_db('forum_question',$con);
if(!$db)
{
die("Cannot connect to the database.");
}

if(isset($_POST['submit']))
{
$result=mysql_query("SELECT * FROM forum_question");
while($row=mysql_fetch_array($result))
{
$add=$row['order']+1;
echo $add;
mysql_query("UPDATE forum_question SET order='$add' WHERE order='$row[order]'");
}

}



echo '
<form method="POST" action="thisScript.php">
<input type="submit" name="submit" value="submit"/>
</form>';

?>

 

 

The problem is, the row order in the table forum_question never updates, it always stays at 0. How would I go about fixing this problem?

Link to comment
https://forums.phpfreaks.com/topic/98019-mysql-update-database-errors/
Share on other sites

First, you shouldn't use ORDER as a column name, as it is a reserved word. Also, you shouldn't use order in your WHERE clause, do you have a unique column like ID?

 

mysql_query("UPDATE forum_question SET `order`='{$add}' WHERE id='{$row['id']}'");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.