Jump to content

Archived

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

kevloink

SQL UPDATE with PHP

Recommended Posts

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.

Share this post


Link to post
Share on other sites
show the code where you actually sending the query (i.e. mysql_query function)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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  :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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???

Share this post


Link to post
Share on other sites

×

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.