php - How to check for a condition before executing MYSQL query? -


i trying check see if condition exists before executing mysql update. code below works:

if (!mysql_query( "update customers set available_credit = available_credit userid = '$userid';" ))  { die('sorry, database error occurred'); } 

...but i'm trying add condition this:

if (!mysql_query && ($tradein_status == 'accepted credit')( "update customers set available_credit = available_credit userid = '$userid';" ))  { die('sorry, database error occurred'); } 

..which doesn't work - generates error: "parse error: syntax error, unexpected '(' in /home/bohemeth/public_html/tradeins/save_tradeins.php on line 235"

the second thing wondering why part:

if (!mysql_query( "update customers set available_credit = available_credit userid = '$userid';" )) 

...not written 2 parens , curly braces after condition, seems anywhere else conditional test, so:

if (!mysql_query){ "update customers set available_credit = available_credit userid = '$userid';" } 

thank help!!

mysql_query function. it's used this: mysql_query('sql query');

it written in question attempt make more readable:

if(!mysql_query( 'sql query' )) 

it written way:

if(!mysql_query('sql query')) 

so, add clause, add before or after mysql_query call.

if($tradein_status == 'accepted credit' && mysql_query('sql query')) 

in if statement {} can omitted. in case, next line 1 ran if case true.

so, finalize:

if($tradein_status == 'accepted credit' && mysql_query('sql query')){     die('sorry, database error occurred'); } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -