Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-22-2008, 04:54 PM   PM User | #1
chornbeck
Regular Coder

 
Join Date: Feb 2006
Posts: 138
Thanks: 11
Thanked 0 Times in 0 Posts
chornbeck is an unknown quantity at this point
UPDATE statement not working correctly

I have the following UPDATE statement:

Code:
$result=MYSQL_QUERY("UPDATE WRGleads SET date2 = '$date2', time2 = '$time2' WHERE phone = '$phonecheck'") or
$phonecheck is a valid variable that can be echoed later in the page. If I remove the WHERE clause, the statement works, updating all rows in the table with the new date and time.

I simply want to only update the rows that are validated by the WHERE clause - this is not working for some reason - can anyone shed any light on this?

Thanks!
Chris
chornbeck is offline   Reply With Quote
Old 07-22-2008, 05:00 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
PHP Code:
$query "UPDATE WRGleads SET date2 = '".$date2."', time2 = '".$time2."' WHERE phone = '".$phonecheck."'";
$result=MYSQL_QUERY($query) or .... 
regards
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
chornbeck (07-22-2008)
Old 07-22-2008, 05:21 PM   PM User | #3
chornbeck
Regular Coder

 
Join Date: Feb 2006
Posts: 138
Thanks: 11
Thanked 0 Times in 0 Posts
chornbeck is an unknown quantity at this point
Thanks for the help! Can anyone tell me WHY this solution works, while mine does not? Is it a matter of the variables being passed incorrectly?

Thanks again!
chornbeck is offline   Reply With Quote
Old 07-22-2008, 05:36 PM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by chornbeck View Post
Thanks for the help! Can anyone tell me WHY this solution works, while mine does not? Is it a matter of the variables being passed incorrectly?

Thanks again!
I apologize, is my fault. Is a matter of quating. The variables between ' are not expanded, only between ". for example:

PHP Code:
$myvar "this var";
echo 
'$myvar'// don't work
echo "$myvar"// this work 
regards
oesxyl is offline   Reply With Quote
Old 07-22-2008, 06:57 PM   PM User | #5
chornbeck
Regular Coder

 
Join Date: Feb 2006
Posts: 138
Thanks: 11
Thanked 0 Times in 0 Posts
chornbeck is an unknown quantity at this point
Thanks for the explanation!
chornbeck is offline   Reply With Quote
Old 07-23-2008, 01:30 PM   PM User | #6
chaosprime
Regular Coder

 
Join Date: Apr 2008
Location: New Jersey
Posts: 116
Thanks: 0
Thanked 29 Times in 29 Posts
chaosprime is an unknown quantity at this point
Well, except that's not what's going on. Since your outer quotes are double quotes, you'll get variable interpolation regardless of the fact that single quotes appear inside them. You can test that with this:

PHP Code:
<?
$foo 
'hi';
echo 
"'$foo'\n";
?>
That will output 'hi' (with the quotes). There actually is no difference between your original query and the solution posted. This is easily tested as well:

PHP Code:
<?
$date2 
'second date';
$time2 'second time';
$phonecheck '555-1212';
$query1 "UPDATE WRGleads SET date2 = '".$date2."', time2 = '".$time2."' WHERE phone = '".$phonecheck."'";
$query2 "UPDATE WRGleads SET date2 = '$date2', time2 = '$time2' WHERE phone = '$phonecheck'";
echo 
$query1 "<br />\n";
echo 
$query2 "<br />\n";
?>
You will get two identical lines of output. If one worked and the other didn't, it's because of some third factor not in evidence.

Sorry to, I'm sure, add to the confusion, but it's not going to help you any to go through life with mistaken ideas about string quoting because of this.
__________________
Chaos
Lost Souls: text based RPG | MUDseek: MUD gaming search | MUDfind: MUD resource sites | Discordian Quotes
chaosprime is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:44 AM.


Advertisement
Log in to turn off these ads.