I am currently using a PHP framework which basically uses a wrapper for PDO, and am stumped on a problem. I have a page which takes any number of post variables, which could be any combination of the following:
":fullname" => $_POST['fullName'],
":universityID" => $_POST['university'],
":gpa" => $_POST['gpa'],
":major" => $_POST['major'],
":gradYear" => $_POST['gradYear'],
":photo" => "",
":description" => $_POST['description'],
"howDidYouHear" => $_POST['howDidYouHear']
And I have an update statement which should look something like this:
$affectedRows = getDatabase()->execute('UPDATE user SET universityID = :universityID,
gpa = :gpa, etc, WHERE fullName=:fullName', array(':universityID' =>
$_POST['universityID'], ':gpa' => $_POST['gpa']));
Now the problem is if I do this sort of update statement I will be overwriting old data in the table, most of which is still valid. What I want to do is only update rows which I have new information for, and not touch the other ones. Is there a way to figure out within the query which ones should and should not be changed?
1 Answer