Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8591733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:35:28+00:00 2026-06-11T23:35:28+00:00

I am currently using a PHP framework which basically uses a wrapper for PDO,

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:35:29+00:00Added an answer on June 11, 2026 at 11:35 pm
    $sets = array();
    $vals = array();
    
    for ($_POST as $key => $value) {
      if ($value == '') { continue; }
      switch ($key) {
      case "university":
        $sets[] = 'universityID = ?';
        $vals[] = $value;
        break;
      case "gpa":
      case "major":
      case "gradYear":
      case "description":
      case "howDidYouHear":
        $sets = "$key = ?";
        $vals = $value;
        break;
      }
    
    $sql = 'UPDATE user SET ' . implode(', ', $sets) . 'WHERE fullname = ?';
    $vals[] = $_POST['fullname'];
    $affectedRows = getDatabase()->execute($sql, $vals);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a PHP CLI script using Zend Framework extensively which seems to
I'm currently using Zend Framework 2 beta for on PHP 5.4.4 to develop a
I am currently working on converting a ColdFusion website, using Fusebox framework, to PHP.
I am currently using PHP/MySQL and the jQuery timeago plugin. Basically, I need to
I am building a custom MVC framework using PHP. My problem is when I
I am currently building an MVC application in PHP (not using any frameworks). I
I am currently working on a big management system (in PHP using Zend Framework,
I'm currently writing my own PHP framework as a learning exercise using the HMVC
I'm currently working on a PHP project using CodeIgniter as my framework. I took
I'm currently designing an application using PHP and MySQL, built on the Kohana framework.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.