Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php mysql modify row data

Options
  • 23-06-2006 7:17pm
    #1
    Registered Users Posts: 673 ✭✭✭


    Hey,

    Im trying to write a script that will alter data stored in a row in a mysql database. Is this how you write the code if you want to change multiple fields at the same time or do i have to do seperate queries?

    Thanks


    [PHP] $sql = "UPDATE washtec_job_information
    SET job_number = ".$job_number."
    SET site_code = ".$site_code."
    SET site_name = ".$site_name."
    SET equip_code = ".$equip_code."
    SET eng = ".$eng."
    SET l_time = ".$l_time."
    SET l_date = ".$l_date."
    SET eq_op = ".$eq_op."
    SET fault_description = ".$fault_description."
    SET station = ".$station."
    WHERE row_id = ".$row_id."
    ";[/PHP]


Comments

  • Registered Users Posts: 250 ✭✭ikoonman


    Your SQL query should be something like:
    UPDATE washtec_job_information SET job_number=1, site_code=2, ... WHERE row_id=4
    

    Naturally I've omitted some fields from your example. Just convert this to your inline code.

    Is this what you are looking for?


  • Registered Users Posts: 683 ✭✭✭Gosh


    You only need one SET, text fields should be enclosed in single quotes and a comma after the field values
    $sql = "UPDATE washtec_job_information
                                SET job_number = '" . $job_number . "',
                                    site_code = '" . $site_code . "',
                                    site_name = '" . $site_name . "',
                                    equip_code = '" . $equip_code . "',
                                    eng = '" . $eng . "'";
                                    etc
                                    etc
    


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Nice one lads, i noticed i was missing the commas yestaerday but when i tried that it still didnt work. I have however left out the bloody ' around the strings..... again!! Me learning PHP is like training a chimp learning brain surgery.


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Arrrgggghhhhhh :mad:

    Now im getting this error:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET site_code = 'STAT-56', SET site

    I have changed the php code to this:
    [PHP] $sql = "UPDATE washtec_job_information
    SET job_number = ".$job_number.",
    SET site_code = '".$site_code."',
    SET site_name = '".$site_name."',
    SET equip_code = '".$equip_code."',
    SET eng = '".$eng."',
    SET l_time = '".$l_time."',
    SET l_date = ".$l_date.",
    SET eq_op = '".$eq_op."',
    SET fault_description = '".$fault_description."',
    SET station = '".$station."'
    WHERE row_id = ".$row_id."
    "; [/PHP]

    Any ideas?


  • Registered Users Posts: 32,136 ✭✭✭✭is_that_so


    Is job number an integer or a literal? If it's not an integer you will need single quotes. Always good to have a quick

    print $sql;
    exit;
    in your code to see what you are trying to insert/update etc.


  • Advertisement
  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    As said above you only use set once.
    Try this:

    [PHP]
    $sql = "UPDATE washtec_job_information
    SET job_number = '".$job_number."',
    site_code = '".$site_code."',
    site_name = '".$site_name."',
    equip_code = '".$equip_code."',
    eng = '".$eng."',
    l_time = '".$l_time."',
    l_date = ".$l_date.",
    eq_op = '".$eq_op."',
    fault_description = '".$fault_description."',
    station = '".$station."'
    WHERE row_id = '".$row_id."'
    ";
    [/PHP]


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Thanks lads, i didnt see that about putting in SET jusy the once. Got it workin now.


Advertisement