title: PHP/Mysql input value on column become null when another column value change
body: <p>I just extend a column on my db table. So I try to put data on that table. I have 10 more column on that table. There is a column name <code>_source_</code> and if its value become 1 then my new column input data correctly. but if its value became 2 then my new column show null. I check and re-check my function from last two days. I can't understand what I am missing!   </p>
  
  <p>Here is my full function PHP code:</p>
  
  <pre><code>function regular_upload($inputname, $ftp_server){
          global $site_url;
          $ok=1;
          $upload_name = $inputname;
          // AICI VERIFICAM DACA A FOST ADAUGATA O FILA
          if (!isset($_FILES[$upload_name])) {
              //header('Location: index.php');
              echo 'No upload found in \$_FILES for ' . $upload_name;
              $ok=0;
              //exit();
          } else if (isset($_FILES[$upload_name]['error']) &amp;&amp; $_FILES[$upload_name]['error'] != 0) {
              // echo $uploadErrors[$_FILES[$upload_name]['error']];
              echo "&lt;p class='error'&gt;No files&lt;/p&gt;";
              $ok=0;
              //exit();
          } else if (!isset($_FILES[$upload_name]['tmp_name']) || !@is_uploaded_file($_FILES[$upload_name]['tmp_name'])) {
              echo "&lt;p class='error'&gt;Upload failed is_uploaded_file test.&lt;/p&gt;";
              $ok=0;
              //exit();
          } else if (!isset($_FILES[$upload_name]['name'])) {
              $ok=0;
              echo "&lt;p class='error'&gt;File has no name.&lt;/p&gt;";
              //exit();
          }
          // DACA ADULT NU E NUMERIC DIEEEEE
          if (isset($_POST['adult']) &amp;&amp; is_numeric($_POST['adult']) &amp;&amp; $_POST['adult'] &gt;= 0 &amp;&amp; $_POST['adult'] &lt;= 1) {
              $adult = $_POST['adult'];
          } else {
              die("You didn't specify if your file(s) are Adult or Non-Adult");
          }
  
          if(is_numeric($_POST['thumb_size_contaner'])) {
              $thumbnail_size = $_POST['thumb_size_contaner'];
          } else {
              die("Injection detected");
          }
  
          if($ok == 1) {
          // verificare tipul de imagini - un fel de whitelist
          $imageinfo = getimagesize($_FILES[$upload_name]['tmp_name']);
          if($imageinfo['mime'] != 'image/gif' &amp;&amp; $imageinfo['mime'] != 'image/jpeg' &amp;&amp; $imageinfo['mime'] != 'image/png' &amp;&amp; $imageinfo['mime'] != 'image/jpg') {
              echo "&lt;p class='error'&gt;Sorry, we only accept GIF, JPEG and PNG images&lt;/p&gt;";
              $ok=0;
              //exit();
          }
          }
  
          if($ok == 1) {
          // blacklist ce nu tre sa fie
          $filename = strtolower($_FILES[$upload_name]['name']);
          $blacklist = array('php', 'php3', 'php4', 'phtml','exe'); #example of black list
  
          foreach ($blacklist as $item) {
              if(preg_match("/$item\$/i", $filename)) {
                  echo "&lt;p class='error'&gt;We do not allow uploading PHP files&lt;/p&gt;";
                  $ok=0;
                  //exit();
              }
          }
          }
  
          if($ok == 1) {
          // de aici setam dimensiunea maxima a imaginii
          list($width, $height, $type, $attr) = getimagesize($_FILES[$upload_name]['tmp_name']);
          if ($width &gt; MAX_UPLOAD_WIDTH || $height &gt; MAX_UPLOAD_HEIGHT)
          {
              echo "&lt;p class='error'&gt;Maximum width and height exceeded. Please upload images below ".MAX_UPLOAD_WIDTH." x ".MAX_UPLOAD_HEIGHT." px size&lt;/p&gt;";
              $ok=0;
              //exit();
          }
          }
  
          if($ok == 1) {
          $q = "SELECT img, thumb FROM sources WHERE id = '1'";
          $result = mysql_query($q);
          if(mysql_num_rows($result) &gt; 0) {
              $rowSources = mysql_fetch_array($result);
          } else {
              die("Something went wrong : ". mysql_error());
          }
  
  
  
          $data_year = date('Y');
          $data_month = date('m');
          $data_day = date('d');
  
              if($ftp_server == 0) {
          $dir = $rowSources['img'] . "/" . $data_year . "/" . $data_month . "/" . "$data_day";
          $dirthumb = $rowSources['thumb'] . "/" . $data_year . "/" . $data_month . "/" . "$data_day";
  
          if(!file_exists($dir) OR !is_dir($dir)){
              mkdir($dir, 0777, true);
          }
  
          if(!file_exists($dirthumb) OR !is_dir($dirthumb)){
              mkdir($dirthumb, 0777, true);
          }
  
          } else {
                  $q = "SELECT * FROM ftp_logins
                  INNER JOIN sources ON ftp_logins.source_id = sources.id
                  WHERE ftp_logins.id = $ftp_server
                  ";
                  $result = mysql_query($q);
                  if(!$result) {
                      echo mysql_error();
                  }
                  $rowFTP = mysql_fetch_assoc($result);
  
                  $dir = $rowFTP['img'] . "/" . $data_year . "/" . $data_month . "/" . "$data_day";
                  $dir2 = $rowFTP['img2'] . "/" . $data_year . "/" . $data_month . "/" . "$data_day";
                  $dirthumb = $rowFTP['thumb'] . "/" . $data_year . "/" . $data_month . "/" . "$data_day";
                  $dirthumb2 = $rowFTP['thumb2'] . "/" . $data_year . "/" . $data_month . "/" . "$data_day";
  
  
  
                  $FTP = new FTP();
                  $FTP-&gt;connect($rowFTP['host'], $rowFTP['user'], $rowFTP['pass']);
                  global $ftp_conn_id;
  
                  if(!$FTP-&gt;directory_exists($ftp_conn_id, "/". $dir)) {
                      $FTP-&gt;mkdir_recusive($ftp_conn_id, "/". $dir);
                  }
                  if(!$FTP-&gt;directory_exists($ftp_conn_id, "/". $dirthumb)) {
                      $FTP-&gt;mkdir_recusive($ftp_conn_id, "/". $dirthumb);
                  }
              }
  
          //$uniquenumber = uniqid('', true);
          $uniquenumber = uniqid();
          $view_id = uniqid();
  
          $target = $dir;
          $extension = pathinfo($_FILES[$upload_name]['name'], PATHINFO_EXTENSION);
          //$filename =  $_FILES['uploaded']['name'];
          $nameimage = $uniquenumber . "." .  $extension;
          $target = $target  . "/"  . $uniquenumber . "." . $extension;
  
  
  
          $uploaded_size = $_FILES[$upload_name]['size'];
  
          //echo $uploaded_size;
  
          //This is our size condition
          if ($uploaded_size &gt; MAX_UPLOAD_SIZE*1024) { // IN KB
              echo "&lt;p class='error'&gt;Your file is too large.&lt;/p&gt;";
              $ok=0;
          }
          }
          //This is our limit file type condition
  
  
  
          if ($ok==0) {
              echo "&lt;p class='error'&gt;Sorry your file was not uploaded &lt;/p&gt;";
          } else {
  
              //If everything is ok we try to upload it
  if($ftp_server == 0) {
  
              if(move_uploaded_file($_FILES[$upload_name]['tmp_name'], $target)) {
                  echo "&lt;p class='success'&gt; ". basename( $_FILES[$upload_name]['name']). " has been succesfuly uploaded &lt;/p&gt;";
  
                  //aici se transforma RESIZE PENTRU THUMBNAIL din $_POST[''];
                  $thumbnail_size_final = 180;
                  switch($thumbnail_size) {
                      case 1:
                          $thumbnail_size_final = SMALL_THUMB;
                          break;
                      case 2:
                          $thumbnail_size_final = MEDIUM_THUMB;
                          break;
                      case 3;
                          $thumbnail_size_final = LARGE_THUMB;
                          break;
                      case 4;
                          $thumbnail_size_final = LARGER_THUMB;
                          break;
                      case 5;
                          $thumbnail_size_final = COVER_THUMB;
                          break;
                  }
  
  
  
                  // aici se face resizeul imaginilor
                  $target_thumb = $dirthumb;
                  $resizeuploadpatch = $target_thumb . "/" . $uniquenumber . "." . $extension ;
                  $image = new SimpleImage();
                  $image-&gt;load($target);
  
                  if($width &gt; $thumbnail_size_final) {
                  $image-&gt;resizeToWidth($thumbnail_size_final);
                  }
  
                  $image-&gt;save($resizeuploadpatch);
  
  
                  $data = date('Y-m-d');
                  //$ImageId = $randomnumber . "-" . $basenameFilesUploaded;
                  //$ThumbSpreImagine = $website . "/" . $thumb . "/" . $ImageId;
  
  
                  //INSERARE IN BAZA DE DATE
                  if(isset($_SESSION['user_id'])) {
                      $user_id = $_SESSION['user_id'];
                  } else {
                      $user_id = 0;
                  }
  
                  if(isset($_SESSION['user_id']) &amp;&amp; isset($_POST['set_gallery']) &amp;&amp; is_numeric($_POST['set_gallery']) &amp;&amp; strlen($_POST['set_gallery']) &gt; 0) {
                      $qG = "SELECT id FROM galleries WHERE id = {$_POST['set_gallery']} AND id_user = {$_SESSION['user_id']}";
                      $resultQg = mysql_query($qG);
                      if($resultQg &amp;&amp; mysql_num_rows($resultQg) &gt; 0){
                          $gallery = $_POST['set_gallery'];
                      } else {
                          $gallery = 0;
                      }
                  } else {
                      $gallery = 0;
                  }
  
                   $titlename = basename( $_FILES[$upload_name]['name']);
                   $titlename2 = $view_id;
  
    $q = "INSERT INTO images (`id_user`, `titlename`, `gallery`,`name`,`view_id`, `date_added`, `last_view`, `source`, `adult`, `thumb_size`, `ftp`) VALUES
                              ('{$user_id}', '{$titlename}', '{$gallery}','{$nameimage}', '{$view_id}', '{$data}', '{$data}', '1', '{$adult}', '{$thumbnail_size}', '{$ftp_server}')";
                  $result = mysql_query($q);
                  $id_inserted = mysql_insert_id();
                  if(!$result) {
                      die("Database error : " . mysql_error());
                  }
  
                  if(isset($_POST['download_links']) &amp;&amp; strlen($_POST['download_links']) &gt; 2) {
                      $download_links = filter($_POST['download_links']);
                      $download_links = trim($download_links);
                      $q = "INSERT INTO images_opt (`id_img`, `download_links`) VALUES ('{$id_inserted}', '{$download_links}')";
                      $result = mysql_query($q);
                      if(!$result) {
                          die("Database error : " . mysql_error());
                      }
                  }
  
                  ?&gt;
  
              &lt;div id="uploadedimage"&gt;
                  &lt;a target='_blank' href="&lt;?php echo "{$site_url}/img-{$view_id}.html"; ?&gt;"&gt;&lt;img border="0" src="&lt;?php echo $site_url . "/" . $resizeuploadpatch; ?&gt;" alt="uploaded_image" /&gt;&lt;/a&gt;
              &lt;/div&gt;
  
              &lt;div id="uploadcodes"&gt;
                  &lt;label&gt;BB Code:&lt;/label&gt;&lt;br /&gt;
                  &lt;input type='text' onclick="this.select();" value="&lt;?php echo "[URL={$site_url}/img-{$view_id}.html][IMG]{$site_url}/{$resizeuploadpatch}[/IMG][/URL] "; ?&gt;"&gt;
                  &lt;br /&gt; &lt;br /&gt;
                  &lt;label&gt;HTML:&lt;/label&gt;&lt;br /&gt;
                  &lt;input type='text' onclick="this.select();" value="&lt;?php echo "&lt;a href='{$site_url}/img-{$view_id}.html'&gt;&lt;img src='{$site_url}/{$resizeuploadpatch}' alt='image' /&gt;&lt;/a&gt; "; ?&gt;"&gt;
                  &lt;br /&gt; &lt;br /&gt;
                  &lt;label&gt;Link:&lt;/label&gt;&lt;br /&gt;
                  &lt;input type='text' onclick="this.select();" value="&lt;?php echo "{$site_url}/img-{$view_id}.html "; ?&gt;"&gt;
                  &lt;?php
                  if(DIRECT_LINK_SHOW == 1) {
                      echo "
                          &lt;br /&gt; &lt;br /&gt;
                          &lt;label&gt;Direct Link to image:&lt;/label&gt;&lt;br /&gt;
                          &lt;input type='text' onclick='this.select();' value='{$site_url}/{$dir}/{$nameimage}'&gt;
                          ";
                  }
                  ?&gt;
              &lt;/div&gt;
  
              &lt;?php
  
                  global $BBCode_global;
                  global $HTMLCode_global;
                  global $DirectLink_global;
                  global $DirectLinkToImg_global;
  
                  $BBCode_global[] = "[URL={$site_url}/img-{$view_id}.html][IMG]{$site_url}/{$resizeuploadpatch}[/IMG][/URL]";
                  $HTMLCode_global[] = "&lt;a href='{$site_url}/img-{$view_id}.html'&gt;&lt;img src='{$site_url}/{$resizeuploadpatch}' alt='image' /&gt;&lt;/a&gt;";
                  $DirectLink_global[] = "{$site_url}/img-{$view_id}.html";
                  $DirectLinkToImg_global[] = "{$site_url}/{$dir}/{$nameimage}";
  
  
                  echo "&lt;div style='display:none;' class='ajax_BBCode'&gt;[URL={$site_url}/img-{$view_id}.html][IMG]{$site_url}/{$resizeuploadpatch}[/IMG][/URL]&lt;/div&gt;";
                  echo "&lt;div style='display:none;' class='ajax_HTMLCode'&gt;&lt;a href='{$site_url}/img-{$view_id}.html'&gt;&lt;img src='{$site_url}/{$resizeuploadpatch}' alt='image' /&gt;&lt;/a&gt;&lt;/div&gt;";
                  echo "&lt;div style='display:none;' class='ajax_DirectLink'&gt;{$site_url}/img-{$view_id}.html&lt;/div&gt;";
                  echo "&lt;div style='display:none;' class='ajax_DirectLinkToImg'&gt;{$site_url}/{$dir}/{$nameimage}&lt;/div&gt;";
  
              } else {
                  echo "&lt;p class='error'&gt;Sorry, there was a problem uploading your file.&lt;/p&gt;";
              }
  
  } else { // if FTP SERVER
      $ftp_temp_img = "cache/ftp/".$nameimage."";
      $ftp_temp_thumb = "cache/ftp/thumb/".$nameimage."";
      if(move_uploaded_file($_FILES[$upload_name]['tmp_name'], $ftp_temp_img)) {
          //aici se transforma RESIZE PENTRU THUMBNAIL din $_POST[''];
          $thumbnail_size_final = 180;
          switch($thumbnail_size) {
              case 1:
                  $thumbnail_size_final = SMALL_THUMB;
                  break;
              case 2:
                  $thumbnail_size_final = MEDIUM_THUMB;
                  break;
              case 3;
                  $thumbnail_size_final = LARGE_THUMB;
                  break;
              case 4;
                  $thumbnail_size_final = LARGER_THUMB;
                  break;
              case 5;
                  $thumbnail_size_final = COVER_THUMB;
                  break;
          }
  
  
  
          // aici se face resizeul imaginilor
          $image = new SimpleImage();
          $image-&gt;load($ftp_temp_img);
  
          if($width &gt; $thumbnail_size_final) {
              $image-&gt;resizeToWidth($thumbnail_size_final);
          }
  
          $image-&gt;save($ftp_temp_thumb);
      }
  
  
      if (ftp_put($ftp_conn_id, "/".$dir . "/$nameimage/", $ftp_temp_img, FTP_BINARY)) {
          //echo "successfully uploaded image $ftp_temp_img in $target\n";
      } else {
          //echo "There was a problem while uploading $ftp_temp_img in $target\n";
      }
  
      if (ftp_put($ftp_conn_id, "/".$dirthumb . "/$nameimage/", $ftp_temp_thumb, FTP_BINARY)) {
          //echo "successfully uploaded image $ftp_temp_thumb in $ftp_temp_thumb\n";
      } else {
          //echo "There was a problem while uploading $ftp_temp_thumb in $dirthumb\n";
      }
  
      $FTP-&gt;disconnect($ftp_conn_id);
  
      unlink($ftp_temp_img);
      unlink($ftp_temp_thumb);
  
  
      $data = date('Y-m-d');
      //$ImageId = $randomnumber . "-" . $basenameFilesUploaded;
      //$ThumbSpreImagine = $website . "/" . $thumb . "/" . $ImageId;
  
  
      //INSERARE IN BAZA DE DATE
      if(isset($_SESSION['user_id'])) {
          $user_id = $_SESSION['user_id'];
      } else {
          $user_id = 0;
      }
  
      if(isset($_SESSION['user_id']) &amp;&amp; isset($_POST['set_gallery']) &amp;&amp; is_numeric($_POST['set_gallery']) &amp;&amp; strlen($_POST['set_gallery']) &gt; 0) {
          $qG = "SELECT id FROM galleries WHERE id = {$_POST['set_gallery']} AND id_user = {$_SESSION['user_id']}";
          $resultQg = mysql_query($qG);
          if($resultQg &amp;&amp; mysql_num_rows($resultQg) &gt; 0){
              $gallery = $_POST['set_gallery'];
          } else {
              $gallery = 0;
          }
      } else {
          $gallery = 0;
      }
  
                   $titlename = basename( $_FILES[$upload_name]['name']);
                   $titlename2 = $view_id;
  
    $q = "INSERT INTO images (`id_user`,  `titlename`, `gallery`,`name`,`view_id`, `date_added`, `last_view`, `source`, `adult`, `thumb_size`, `ftp`) VALUES
                              ('{$user_id}', '{$titlename}', '{$gallery}','{$nameimage}', '{$view_id}', '{$data}', '{$data}', '1', '{$adult}', '{$thumbnail_size}', '{$ftp_server}')";
      $result = mysql_query($q);
      $id_inserted = mysql_insert_id();
      if(!$result) {
          die("Database error : " . mysql_error());
      }
  
      if(isset($_POST['download_links']) &amp;&amp; strlen($_POST['download_links']) &gt; 2) {
          $download_links = filter($_POST['download_links']);
          $download_links = trim($download_links);
          $q = "INSERT INTO images_opt (`id_img`, `download_links`) VALUES ('{$id_inserted}', '{$download_links}')";
          $result = mysql_query($q);
          if(!$result) {
              die("Database error : " . mysql_error());
          }
      }
  
      ?&gt;
  
  &lt;div id="uploadedimage"&gt;
      &lt;a target='_blank' href="&lt;?php echo "{$site_url}/img-{$view_id}.html"; ?&gt;"&gt;&lt;img border="0" src="&lt;?php echo "{$rowFTP['url']}/{$dirthumb2}/{$nameimage}"; ?&gt;" alt="uploaded_image" /&gt;&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;div id="uploadcodes"&gt;
      &lt;label&gt;BB Code:&lt;/label&gt;&lt;br /&gt;
      &lt;input type='text' onclick="this.select();" value="&lt;?php echo "[URL={$site_url}/img-{$view_id}.html][IMG]{$rowFTP['url']}/{$dirthumb2}/{$nameimage}[/IMG][/URL] "; ?&gt;"&gt;
      &lt;br /&gt; &lt;br /&gt;
      &lt;label&gt;HTML:&lt;/label&gt;&lt;br /&gt;
      &lt;input type='text' onclick="this.select();" value="&lt;?php echo "&lt;a href='{$site_url}/img-{$view_id}.html'&gt;&lt;img src='{$rowFTP['url']}/{$dirthumb2}/{$nameimage}' alt='image' /&gt;&lt;/a&gt; "; ?&gt;"&gt;
      &lt;br /&gt; &lt;br /&gt;
      &lt;label&gt;Link:&lt;/label&gt;&lt;br /&gt;
      &lt;input type='text' onclick="this.select();" value="&lt;?php echo "{$site_url}/img-{$view_id}.html "; ?&gt;"&gt;
      &lt;?php
      if(DIRECT_LINK_SHOW == 1) {
          echo "
                          &lt;br /&gt; &lt;br /&gt;
                          &lt;label&gt;Direct Link to image:&lt;/label&gt;&lt;br /&gt;
                          &lt;input type='text' onclick='this.select();' value='{$rowFTP['url']}/{$dir2}/{$nameimage}'&gt;
                          ";
      }
      ?&gt;
  &lt;/div&gt;
  
  &lt;?php
  
      global $BBCode_global;
      global $HTMLCode_global;
      global $DirectLink_global;
      global $DirectLinkToImg_global;
  
      $BBCode_global[] = "[URL={$site_url}/img-{$view_id}.html][IMG]{$rowFTP['url']}/{$dirthumb2}/{$nameimage}[/IMG][/URL]";
      $HTMLCode_global[] = "&lt;a href='{$site_url}/img-{$view_id}.html'&gt;&lt;img src='{$rowFTP['url']}/{$dirthumb2}/{$nameimage}' alt='image' /&gt;&lt;/a&gt;";
      $DirectLink_global[] = "{$site_url}/img-{$view_id}.html";
      $DirectLinkToImg_global[] = "{$rowFTP['url']}/{$dir2}/{$nameimage}";
  
      echo "&lt;div style='display:none;' class='ajax_BBCode'&gt;[URL={$site_url}/img-{$view_id}.html][IMG]{$rowFTP['url']}/{$dirthumb2}/{$nameimage}[/IMG][/URL]&lt;/div&gt;";
      echo "&lt;div style='display:none;' class='ajax_HTMLCode'&gt;&lt;a href='{$site_url}/img-{$view_id}.html'&gt;&lt;img src='{$rowFTP['url']}/{$dirthumb2}/{$nameimage}' alt='image' /&gt;&lt;/a&gt;&lt;/div&gt;";
      echo "&lt;div style='display:none;' class='ajax_DirectLink'&gt;{$site_url}/img-{$view_id}.html&lt;/div&gt;";
      echo "&lt;div style='display:none;' class='ajax_DirectLinkToImg'&gt;{$rowFTP['url']}/{$dir2}/{$nameimage}&lt;/div&gt;";
  
  } // ftp end
  
  
  
  
  
          } // ELSE IF EVERYTING IS OK, IF ERROR = 0
      } // END FUNCTION
  </code></pre>
  
  <p>I am really frustrated with this and I can't find what is causing the error.</p>
  
  <p>Here is the <strong>database</strong> screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/YySgC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YySgC.jpg" alt="Here is database screenshot"></a></p>