Jump to content


Photo

SQL UPDATE with PHP


  • Please log in to reply
5 replies to this topic

#1 kevloink

kevloink
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 26 October 2006 - 04:41 AM

This is my code
$sql = "UPDATE 'phpbb_users' SET 'user_points' = '$after_bet_points' WHERE 'username' = 'kevloink';";

But it doesn't do anything at all.

Can you please help, I have been trying for about 40 mins.

#2 mb81

mb81
  • Members
  • PipPipPip
  • Advanced Member
  • 120 posts

Posted 26 October 2006 - 04:44 AM

show the code where you actually sending the query (i.e. mysql_query function)

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 06:04 AM

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:
$sql = "UPDATE phpbb_users SET user_points = '$after_bet_points' WHERE username = 'kevloink'";

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?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 cunoodle2

cunoodle2
  • Members
  • PipPipPip
  • Advanced Member
  • 602 posts

Posted 26 October 2006 - 07:52 AM

Try this out and see if this helps you...

   //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 />";
   }


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  :)

If the code was working and now it's not, something changed. Did you change any code?

yeah, just a little bit, I am trying to start from beginning and trace my steps to see what i did wrong unless you see it.


#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 08:27 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 cunoodle2

cunoodle2
  • Members
  • PipPipPip
  • Advanced Member
  • 602 posts

Posted 28 October 2006 - 06:53 AM

okay that whole limit 1 thing is debatable


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.

but breaking out of the string and concactonating the variable to it like that is totally unecessary.


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.

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.


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???

If the code was working and now it's not, something changed. Did you change any code?

yeah, just a little bit, I am trying to start from beginning and trace my steps to see what i did wrong unless you see it.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users