Welcome to WebmasterWorld Guest from 54.196.248.186

Forum Moderators: open

Message Too Old, No Replies

Sql Update statement

     

JuicyScript

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

5+ Year Member



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

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

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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

rocknbil

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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

JuicyScript

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

5+ Year Member



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

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month