DannyM Posted March 26, 2008 Share Posted March 26, 2008 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 More sharing options...
rhodesa Posted March 26, 2008 Share Posted March 26, 2008 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']}'"); Link to comment https://forums.phpfreaks.com/topic/98019-mysql-update-database-errors/#findComment-501530 Share on other sites More sharing options...
DannyM Posted March 26, 2008 Author Share Posted March 26, 2008 Ah, ok. Thanks, that solved it. I had forgotten about the ORDER word in mysql. Thanks! Link to comment https://forums.phpfreaks.com/topic/98019-mysql-update-database-errors/#findComment-501535 Share on other sites More sharing options...
revraz Posted March 26, 2008 Share Posted March 26, 2008 Putting mysql_error() after your querries would have told you the exact error. Link to comment https://forums.phpfreaks.com/topic/98019-mysql-update-database-errors/#findComment-501544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.