...

View Full Version : Conditional sql statement



mbarandao
07-05-2011, 03:28 AM
Hello,

I'm trying to write a sql statement that would update a record only if a particular row's column is empty; else, insert a new record.

Is this doable?

Currently, I have this update statement:


//query for additional cars 1
$mysql_query=("UPDATE additional_cars SET clientID='$edit_clientID', registeredstate='$edit_registeredstate',
dhtmlgoodies_category='$dhtmlgoodies_categoryupdate', dhtmlgoodies_subcategory='$dhtmlgoodies_subcategoryupdate',caryear='$edit_caryear', servicearea='$lastservice',
currentmileage='$edit_currentmileage', todays_date='$date2', time='$time2', servicedescription='$inputbox2', service='$edit_servicearea_str', servicedesc =CONCAT('$inputbox', servicedesc) WHERE id='$edit_sel_id'");
$result=mysql_query($mysql_query);
if(!$result){die("Error: ".mysql_error());
$id=LAST_INSERT_ID();


How can I modify the above to achieve the outcome mentioned.
Any thoughts!

Lourdrealm19
07-05-2011, 11:46 AM
can i have all the column names of this table. thanks :)

mbarandao
07-05-2011, 02:32 PM
Thanks for the reply;

here are the columns for the table

company
firstname
lastname
contactperson
address
city
state
zipcode
currentmileage
drivenmileage
dhtmlgoodies_category
dhtmlgoodies_subcategory
caryear
clientID
customerid
registeredstate
servicearea
service
servicedesc
servicedescription
todays_date
invoicenum
firstname_initial
time

mbarandao
07-11-2011, 01:57 PM
got it resolved!

thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum