homepage Welcome to WebmasterWorld Guest from 54.198.135.17
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Sql Update statement
JuicyScript




msg:4263692
 5:01 pm on Feb 7, 2011 (gmt 0)

Is it possible to have an sql statement like this?
With the if condition statement in between

$sqlQuery = "UPDATE `members` SET
if ($basic = english)
`basic` = '".$basic."',
else
`basic` = '""',
endif;
`school` = '".$school."'
WHERE `member_id` =
".$_SESSION['SESS_MEMBER_ID'];
$result = mysql_query($sqlQuery) or die(mysql_error());

 

LifeinAsia




msg:4263713
 5:30 pm on Feb 7, 2011 (gmt 0)

You'll need an AND in there (between the `basic` = and `school` = parts).

rocknbil




msg:4263717
 5:36 pm on Feb 7, 2011 (gmt 0)

It would be simpler to do it programmatically.

$basic=($basic=='english')?$basic:'';
// or better yet, case insensitive
// $basic=(preg_match('/english/i',$basic))?$basic:'';
$sqlQuery = "UPDATE `members` SET `basic` = '$basic', `school` = '$school' WHERE `member_id` = ".$_SESSION['SESS_MEMBER_ID'];

Note that concatenation is not needed with $scalar_variables.

LifeinAsia




msg:4263820
 7:48 pm on Feb 7, 2011 (gmt 0)

(And ignore my previous message- didn't have enough coffee in my yet and I mis-read the statement...)

JuicyScript




msg:4263928
 9:45 pm on Feb 7, 2011 (gmt 0)

hello rocknbil
i knw this section is not php but what i what to do is to compare the variable with the field name and if they match it is inserted in the database else nothing is inserted

$basic=($basic=='english')?$basic:'';
// or better yet, case insensitive
// $basic=(preg_match('/english/i',$basic))?$basic:'';
$sqlQuery = "UPDATE `members` SET `basic` = '$basic', `school` = '$school' WHERE `member_id` = ".$_SESSION['SESS_MEMBER_ID'];

rocknbil




msg:4264231
 5:01 pm on Feb 8, 2011 (gmt 0)

See your post in PHP - I *think* I got what you wanted there. :-)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved