How to update nothing in an update fuction in PHP? -


i have form user details updated. once page uploads user few fields loaded current database values.

i can allow them upload images, it's optional. once form submitted fields updated problem images. how can not update image field @ still use in update function have.

is possible way of doing ?

if (empty($_files['logo']['name'])) {     // no file selected upload, (re)action goes here } 

this function:

public function update_header($pagetitle,$title, $slogan, $logo, $titlechoice, $sloganchoice, $logochoice){     global $pdo;      $sql= "update `header` set `pagetitle`=?,`title`=?,`slogan`=?,`logo`=?,`titlechoice`=?,`sloganchoice`=?,`logochoice`=? `header_id` =1";      $query = $pdo->prepare($sql);      $query -> execute(array($pagetitle,$title, $slogan, $logo, $titlechoice, $sloganchoice, $logochoice));      return "has been updated!!"; } 

any ideas?

how can not update image field @ still use in update function have.

if can't modify update_header() function it's not possible. thing is, sql query inside function affects logo field. either value pass in $logo parameter in update_header function converted string (pdo::param_str), , replace current value of logo field.

if can modify update_header() function... 1 way of handling optional field place if (empty($_files['logo']['name'])) { clause inside function , distinguish behavior based on value, e.g.:

public function update_header($pagetitle, $title, $slogan, $logo, $titlechoice, $sloganchoice, $logochoice) {     global $pdo;      if ( ! empty($logo) {         $sql= "update `header` set `pagetitle`=?,`title`=?,`slogan`=?,`logo`=?,`titlechoice`=?,`sloganchoice`=?,`logochoice`=? `header_id` =1";         $query = $pdo->prepare($sql);         $query->execute(array($pagetitle,$title, $slogan, $logo, $titlechoice, $sloganchoice, $logochoice));     } else { // logo empty, not update field         $sql= "update `header` set `pagetitle`=?,`title`=?,`slogan`=?,`titlechoice`=?,`sloganchoice`=?,`logochoice`=? `header_id` =1";         $query = $pdo->prepare($sql);         $query->execute(array($pagetitle,$title, $slogan, $titlechoice, $sloganchoice, $logochoice));     }     // ... 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -