Jump to content

SQL UPDATE with PHP


kevloink

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.