kevloink Posted October 26, 2006 Share Posted October 26, 2006 This is my code[code]$sql = "UPDATE 'phpbb_users' SET 'user_points' = '$after_bet_points' WHERE 'username' = 'kevloink';";[/code]But it doesn't do anything at all.Can you please help, I have been trying for about 40 mins. Quote Link to comment https://forums.phpfreaks.com/topic/25133-sql-update-with-php/ Share on other sites More sharing options...
mb81 Posted October 26, 2006 Share Posted October 26, 2006 show the code where you actually sending the query (i.e. mysql_query function) Quote Link to comment https://forums.phpfreaks.com/topic/25133-sql-update-with-php/#findComment-114597 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 first off, you query has some quotes in there that shouldn't be in there. Don't put quotes around table or field names. Use backticks ` ` if you want, though it's not necessary unless you are using reserved words as names (which you shouldn't do in the first place). It should look like this:[code]$sql = "UPDATE phpbb_users SET user_points = '$after_bet_points' WHERE username = 'kevloink'";[/code]2nd, as mentioned above: all you have shown is the query string. Where do you connect to your database? Where do you actually perform the query? Quote Link to comment https://forums.phpfreaks.com/topic/25133-sql-update-with-php/#findComment-114612 Share on other sites More sharing options...
cunoodle2 Posted October 26, 2006 Share Posted October 26, 2006 Try this out and see if this helps you...[code] //create the SQL query $sql = "UPDATE `phpbb_users` SET `user_points` = '".$after_bet_points."' WHERE `username` = 'kevloink' LIMIT 1;"; //do a little error checking to make sure it works if (mysql_query($sql)) { echo "Profile Successfully updated.<br />"; } //here is what happens if there is an error with your SQL statement else { echo "Error in Profile update.<br />"; }[/code]I changed up the sql statement a little bit with some changes with quotes and such. Also I added the "LIMIT 1" to the end of the statement. It is always a good idea to add that at the end just to make sure that you do not mess up your database with a bad update statement. Worst case you only "mess up" 1 line and not the entire table. Good luck :) Quote Link to comment https://forums.phpfreaks.com/topic/25133-sql-update-with-php/#findComment-114632 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 okay that whole limit 1 thing is debatable, but breaking out of the string and concactonating the variable to it like that is totally unecessary. and again, the backticks aren't necessary unless you are naming your tables and fields names that are reserved words..which is bad coding practice in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/25133-sql-update-with-php/#findComment-114639 Share on other sites More sharing options...
cunoodle2 Posted October 28, 2006 Share Posted October 28, 2006 [quote author=Crayon Violent link=topic=112751.msg457831#msg457831 date=1161851238]okay that whole limit 1 thing is debatable[/quote]I often use the LIMIT 1 thing just for testing to make sure that there are not errors in my queries. I do think that it is a good thing for a new person to be using just to make sure that they do not screw anything up in their database..that is all.[quote author=Crayon Violent link=topic=112751.msg457831#msg457831 date=1161851238]but breaking out of the string and concactonating the variable to it like that is totally unecessary.[/quote]Yes unnecessary however I think that it makes it a little bit easier to read when people are trying to learn and such..that is all.[quote author=Crayon Violent link=topic=112751.msg457831#msg457831 date=1161851238]the backticks aren't necessary unless you are naming your tables and fields names that are reserved words..which is bad coding practice in the first place. [/quote]I thought I read somewhere that the ticks were also used in the event that you had a space in the name of your table (something I would never do anyway) but there is a very good chance then that I am wrong on that one.kevloink, have you had any luck with this??? Quote Link to comment https://forums.phpfreaks.com/topic/25133-sql-update-with-php/#findComment-115737 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.