Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    341
    Thanks
    22
    Thanked 1 Time in 1 Post

    Conditional sql statement

    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:

    PHP Code:
    //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!
    Last edited by mbarandao; 07-05-2011 at 02:27 PM.

  • #2
    New to the CF scene
    Join Date
    Jul 2011
    Location
    Philippines
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can i have all the column names of this table. thanks

  • #3
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    341
    Thanks
    22
    Thanked 1 Time in 1 Post
    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

  • #4
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    341
    Thanks
    22
    Thanked 1 Time in 1 Post
    got it resolved!

    thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •