Comptons_Eazy_E Posted November 21, 2009 Share Posted November 21, 2009 Note: I'm a newbie at PHP/MYSQL just started 3 days ago Anyway Can someone tell me why this code is not working?: $sql="UPDATE players SET Linked = '1' WHERE Name = 'PN' VALUES ('$_POST[fname]')"; mysql_query(sql); Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/ Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 You're missing a $ for the variable $sql on this line: mysql_query(sql); You're also using wrong syntax for updating a database. Try: $sql = "UPDATE players SET Linked='1' WHERE Name='PN'"; Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962279 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 You're missing a $ for the variable $sql on this line: mysql_query(sql); Thanks, but i have tried that. The row doesn't change at all! Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962281 Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 You're also not using the correct syntax for updating (I edited my last post already). Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962285 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 You're also not using the correct syntax for updating (I edited my last post already). Thanks again, i inserted it and it looked like this: $sql = "UPDATE players SET Linked='1' WHERE Name='PN'"; VALUES ('$_POST[fname]')"; mysql_query($sql); I received a error: Parse error: syntax error, unexpected '"' in /www/110mb.com/s/o/u/t/h/w/e/s/southwestrp/htdocs/link.php on line 31 Doing a quick study i commented the two lines that look like this: VALUES ('$_POST[fname]')"; Then it worked, but the row still didn't change, Any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962289 Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 Are you sure the column names in the query are correct (they are case sensitive), and that there is actually a record with the Name 'PN'? Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962290 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 Are you sure the column names in the query are correct (they are case sensitive), and that there is actually a record with the Name 'PN'? Sorry i don't know alot about PHP, I know more about the pawn language, can please explain how do i make it a record?? Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962292 Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 A record is just a row in the database, you do have rows already inserted, right? Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962294 Share on other sites More sharing options...
Andy-H Posted November 21, 2009 Share Posted November 21, 2009 change: mysql_query($sql); //to mysql_query($sql) or trigger_error(mysql_error() . 'on line: ' . __LINE__, E_USER_ERROR); Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962295 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 A record is just a row in the database, you do have rows already inserted, right? Yes i do. This?: By eazy_efolife at 2009-11-20 Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962297 Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 Based on that screenshot it doesn't look like you have a record with the Name 'PN', so of course no records will be updated. Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962298 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 Based on that screenshot it doesn't look like you have a record with the Name 'PN', so of course no records will be updated. oh, I was a bit confused then, also this is what it looks like now: $sql = "UPDATE players SET Linked='1' WHERE Name='Linked'"; //VALUES //('$_POST[fname]')"; mysql_query($sql) or trigger_error(mysql_error() . 'on line: ' . __LINE__, E_USER_ERROR); Those are commented because everytime i uncomment it i get errors Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962299 Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 Yea, those two lines aren't supposed to be there. When I posted the query before that's all that was supposed to be in it, you can completely remove those lines. (Again) Based on that screenshot all I see is 1 record with the Name 'Eric_Wright', and do you even have a column named 'Linked'? I can't tell from the screenshot. Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962302 Share on other sites More sharing options...
Andy-H Posted November 21, 2009 Share Posted November 21, 2009 $sql = "UPDATE players SET Linked='1' WHERE Name='Linked'"; mysql_query($sql) or trigger_error(mysql_error() . 'on line: ' . __LINE__, E_USER_ERROR); You only have one record in the table and the "Name" filed does not contain the string "Linked" it contains the string "Eric_Wright". $sql = "UPDATE players SET Linked='1' WHERE Name='Linked'"; mysql_query($sql) or trigger_error(mysql_error() . 'on line: ' . __LINE__, E_USER_ERROR); printf("Query 1: Records updated: %d ", mysql_affected_rows()); $sql = "UPDATE players SET Linked='1' WHERE Name='Eric_wright'"; mysql_query($sql) or trigger_error(mysql_error() . 'on line: ' . __LINE__, E_USER_ERROR); printf("Query 2: Records updated: %d ", mysql_affected_rows()); Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962306 Share on other sites More sharing options...
Gayner Posted November 21, 2009 Share Posted November 21, 2009 What akon song are u reading? Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962307 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 What akon song are u reading? I wanna love you =) $sql = "UPDATE players SET Linked='1' WHERE Name='Linked'"; mysql_query($sql) or trigger_error(mysql_error() . 'on line: ' . __LINE__, E_USER_ERROR); You only have one record in the table and the "Name" filed does not contain the string "Linked" it contains the string "Eric_Wright". $sql = "UPDATE players SET Linked='1' WHERE Name='Linked'"; mysql_query($sql) or trigger_error(mysql_error() . 'on line: ' . __LINE__, E_USER_ERROR); printf("Query 1: Records updated: %d ", mysql_affected_rows()); $sql = "UPDATE players SET Linked='1' WHERE Name='Eric_wright'"; mysql_query($sql) or trigger_error(mysql_error() . 'on line: ' . __LINE__, E_USER_ERROR); printf("Query 2: Records updated: %d ", mysql_affected_rows()); Sorry for the late reply i was busy, anyway Its hard to explain but everybody has there own account, I was testing the database to see if i can the Linked from 0 to 1. People register there account ingame ( SA-MP is the game http://www.sa-mp.com ) And So I want them to link there account online using my website for my game server. So I just don't want it for my name, for the other people too understand? So when you wrote: WHERE Name='Eric_wright' I didnt just want it for me only thats why i put %_post from the input box text! edit: Yes i do have one coll-um named "Linked" Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962315 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 Thank you all for helping out, I have found the problem and it works now! Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962333 Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 By the way, there's a topic solved feature, you can mark your topic as solved with the button at the bottom left of the page. Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962334 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 By the way, there's a topic solved feature, you can mark your topic as solved with the button at the bottom left of the page. Thanks do i have to make a topic for a simple question? ( How do i change php echo function into a color? ) Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962337 Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 That's HTML/CSS, not PHP. Example: echo "<span style='color: red;'>Red Text!</span>"; Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962340 Share on other sites More sharing options...
Comptons_Eazy_E Posted November 21, 2009 Author Share Posted November 21, 2009 That's HTML/CSS, not PHP. Example: echo "<span style='color: red;'>Red Text!</span>"; =) Quote Link to comment https://forums.phpfreaks.com/topic/182350-solved-whats-wrong-with-this-code/#findComment-962342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.