title: form save empty value php
body: <p>I have created a profile page in php, where the user, using a form can save his telephone number in a table named profile in database. If the user decides to change his telephone number can easily go to form change it and save it again. My only problem is the following. Suppose that the user wants to delete his telephone number. If he goes to the form delete his number (makes the field empty) and press save , the telephone number doesn't change to an empty value and continues to keep the previous number. Any idea how to change this in order to keep an empty value?</p>
  
  <p>This is my code with the form :</p>
  
  <pre><code>&lt;form   action=""   method="POST"  &gt;    
  
  &lt;?php
  
  if ( isset($_GET['success']) === true &amp;&amp; empty($_GET['success'])===true ){
     echo'Profile Updated Sucessfuly';
      }else{
     if( empty($_POST) === false  &amp;&amp;  empty($errors) === true ){
       $update_data_profile = array('telephone' =&gt; $_POST['telephone']);
  
            update_user_profile($session_user_id, $update_data_profile);
        header('Location: profile_update.php?success');                               
        exit();
  
     }else if ( empty($errors) === false ){
        echo output_errors($errors);
         }
  
       ?&gt;
  
   Telephone&lt;input name="telephone" type="text" size="25"  value="&lt;?php echo $user_data_profile['telephone']; ?&gt;"/&gt;
  &lt;input type="submit" value="" name="submit"/&gt;
  &lt;/form&gt; 
  </code></pre>
  
  <p>And this is my function that dispatches data to profile table:</p>
  
  <pre><code>function update_user_profile($user_id, $update_data_profile){
  
    $result = mysql_query("select user_id from profile where user_id = $user_id limit 1");
  
    if(mysql_num_rows($result) === 1){
  
    $update = array();
        array_walk($update_data_profile, 'array_sanitize');
  
    foreach($update_data_profile as $field =&gt; $data ){
      if(!empty($data)){
        $update[]='`' . $field . '` = \'' . $data . '\'';
      }
    }
  
    if(isset($update) &amp;&amp; !empty($update)){
  
    mysql_query(" UPDATE `profile` SET " . implode(',  ', $update) . " WHERE `user_id` = $user_id ") or die(mysql_error());
  }
     }
    else{
  
  $user_id = $update_data_profile['user_id'] ;
  
  if(count($update_data_profile)){
  
  $columns = array();
  $values = array();
  
      foreach($update_data_profile as $field =&gt; $data){
      $columns[] = $field;
      $values[] = $data;
      } 
  }
  
  mysql_query(" INSERT INTO `profile` (" . implode(",", $columns) .") values ('" . implode("','", $values) . "')" ) or die (mysql_error());
  
  }
  
  }
  </code></pre>