![]() |
Updating A Database
Hello,
I've been messing around with this query for a while now and can't get it to work as intended! Code:
$query = 'UPDATE althlete SET Edit: $ud_athletenumber is a hidden form field which contains the autonumber. Any help appreciated. - Steven |
One problem is that, I think, mySQL doesn't like double quotes. However, you'll never get a match because variables in single quoted strings aren't escaped.
So: SQL Code:
SQL Code:
|
Quote:
Code:
$query = 'UPDATE althlete SET |
As I said, MySQL doesn't like double-quotes. Try:
PHP Code:
|
Thanks Robert, but still nothing. I'm not receiving any error, it's just not updating for some reason. Are the backslashes used to escape or separate the quotes?
|
I personally use double quotes and they seem to work for me. One thing that looks a bit weird is the table name. Is that correct?
SQL Code:
SQL Code:
One more thing, you have an extra comma before the WHERE clause. PHP Code:
PHP Code:
|
Thanks for that Bill.
"Athlete" is spelt wrong in the table, I know, instead of changing it I just made the query match it, so the problem doesn't lie there. I have also removed that last comma, then changed the last line to the way Robert had wrote. So: Code:
place = "'.mysql_real_escape_string($place).'"Code:
place = "'.mysql_real_escape_string($place).'"Thanks a lot Steven |
Crap... I copied the wrong text... Sorry about that.
|
Quote:
|
StevenF.
Try this one below and see if it helps. Note the way i´ve put (') and ("). This is how i usally do it. but also with sprintf sometimes. and i found that you used an extra "," comma on the last column to be updated before the WHERE clause. Guess that could be a problem. And make sure all table and column names are correct PHP Code:
|
EyeDentify, thanks for that. I have already solve the problem though, it's a few posts up. I basically have what you have, but with the quotes in the original order. :-)
|
Now see, this is where using string formatting can make things much easier to handle. Compare all of the examples above to:
PHP Code:
|
I like that method Salathe. I may try to start using it. It seems to be quite a bit cleaner.
I do have a question though. Is there a significant (if any) performance penalty using this method as you are calling another function - sprintf - to assign the value of $query? |
Thanks Salathe, I've never seen it done that way before. I'm really knew to php so I have a lot to learn.
Can I ask what the "%s and %d is please? |
The formatting codes are explained in PHP Manual: sprintf. Of course there is a performance penalty to calling a function over, say, concatenating strings. However, the gain in code readability (and time spent not looking for the typing mistakes!!!) far outweighs the extra tiny fractions of a second.
|
%s and %d and so on can be used to specify what the expected input it when using sprintf for example
PHP Code:
|
Point taken Salathe. It does seem better than the way I have been doing it.
|
| All times are GMT. The time now is 03:22 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0