shlocko Posted July 7, 2013 Share Posted July 7, 2013 OKay so I am trying to make this simply update my mysql server. Can anyone maybe see why this isn't working? The code all works perfectly up until while statement... So if someone maybe sees something wrong? Thanks... <? session_start(); include('nconnect.php'); $uname=$_POST['to']; $result = mysqli_query($con, "SELECT * FROM messages WHERE to='{$uname}' "); $content=$_POST['content']; while($row = mysqli_fetch_array($result)){ mysqli_query($con, "UPDATE messages SET content='{$content}' WHERE to='{$uname}' "); header('location: p1.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/279930-update-mysql/ Share on other sites More sharing options...
denno020 Posted July 7, 2013 Share Posted July 7, 2013 What doesn't happen that you are expecting to happen? Also, the while loop will only fire one query, because as soon as you call the query, you're redirecting the user to p1.php.. So it will only update one record, but maybe that was your intention? Link to comment https://forums.phpfreaks.com/topic/279930-update-mysql/#findComment-1439754 Share on other sites More sharing options...
Barand Posted July 7, 2013 Share Posted July 7, 2013 You should check the output from mysql_error() function and you will find you have a syntax error in the query. "TO" is a mysql reserved word. If you must use it as a column name it needs to be inside backticks (`to`) Link to comment https://forums.phpfreaks.com/topic/279930-update-mysql/#findComment-1439755 Share on other sites More sharing options...
shlocko Posted July 7, 2013 Author Share Posted July 7, 2013 Ooh okay, thanks so much for the help, I was so confused because I've used this exact code a hundred other times and it's worked, then it just kinda stopped, thanks for clarifying that for me! Link to comment https://forums.phpfreaks.com/topic/279930-update-mysql/#findComment-1439808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.