简体   繁体   中英

From 6 different fields update or insert values into database

Using PHP and Mysql How would you allow users to update or insert information about themselves from six fields. Eg about, name, website and more? . Would you first use a loop to find all the fields which the user wants to update then query the database with insert or update statements depending if the field is null or an exsisting value has to be overridden.

Example

$Name ; //exsisting value
$email; // existing value
$about;  //fields null
$website;  // user wants to update this field


protected function updateWebsiteinformation($website,$updateArray){

          $this->setTable('userinformation'); //sets Table
          $where = "website = $website";  //where statment
          return $this->update($updateArray, $where); returns statement

there's something funny about your "where" statement. You should have use unique table field instead of field that your users want to update. And for updating process, i would rather update all field at once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM