php - Need Help To Solve Images Disppeared After Again Form Submiitted? -


i have multiple image upload options in form , working fine , update file name in mysql database columns?

when uploads image1 image move on server , showing next html table columns problem when upload image file option2 after form submit image1 on next image1 file option disappeared , in mysql database image1 columns blank?

multiple images uploading functions

 $id=$_request['id'];   if(isset($_post['submit']))  {   if (!empty($_files['image']['name']))   {   $rnd_1 = rand(11111,99999);   $file_name= $rnd_1.'_'.$_files['image']["name"];  $file_path = "uploads/";   $image = new imgmark();   $image->font_path = "arial.ttf";   $image->font_size = 25;   $image->water_mark_text = "© www.edge.pk";    $image->color = 'cc003e';   $image->opacity = 50;   $image->rotation = 0;  if($image->convertimage('image', $file_name, $file_path))  $demo_image = $image->img_path;  }   if (!empty($_files['image1']['name']))   {   $rnd_1 = rand(11111,99999);   $file_name= $rnd_1.'_'.$_files['image1']["name"];  $file_path = "uploads/";   $image = new imgmark();   $image->font_path = "arial.ttf";   $image->font_size = 35;   $image->water_mark_text = "© www.edge.pk";    $image->color = 'cc003e';   $image->opacity = 50;   $image->rotation = 0;  if($image->convertimage('image1', $file_name, $file_path))  $demo_image2 = $image->img_path;  }   if (!empty($_files['image2']['name']))   {   $rnd_1 = rand(11111,99999);   $file_name= $rnd_1.'_'.$_files['image2']["name"];  $file_path = "uploads/";   $image = new imgmark();   $image->font_path = "arial.ttf";   $image->font_size = 35;   $image->water_mark_text = "© www.edge.pk";    $image->color = 'cc003e';   $image->opacity = 50;   $image->rotation = 0;  if($image->convertimage('image2', $file_name, $file_path))  $demo_image3 = $image->img_path;   } 

update query

update products set  image='$demo_image',addimage1='$demo_image2',addimage2='$demo_image3' id='$id' } 

select images query

$query1=mysql_query("select images,addimages1,addimages2 products  id='$id' ")or die("query"); $row2=mysql_fetch_array($query1);  <form method="post" enctype="multipart/form-data">   image upload option1 <input type="file" name="image" id="image" /> <img src="<?php echo $image['image'] ?>" width="150" height="150" />  image upload option2 <input  type="file" name="image1" id="image1"/> <img src="<?php echo $image['addimage1'] ?>" width="150" height="150" />  image upload option3 <input  type="file" name="image2" id="image2"/> <img src="<?php echo $image['addimage2'] ?>" width="150" height="150" />  <input type="submit" class="bg" name="submit" /> </form> 

the problem lays here:

update products set  image='$demo_image',addimage1='$demo_image2',addimage2='$demo_image3' id='$id' } 

from understood first submit form upload first image , submit form again upload second image. reason of during second upload variable $demo_image blank because not sending value of input "image" during resubmit. see here:

$demo_image = $image->img_path; 

$image->img_path blank, therefore $demo_image blank (or null? - not sure) well.

there many solutions of problem. can retrieve data db form , resubmit, or test if variables blank (or null?) , having different update commands different variations, or retrieving data mysql before run update , many more.

i'd pick retrieving "old" data mysql , test if null. if not null in mysql, resubmit same data db. this:

if ($demo_image_from_db!=null) $demo_image = $demo_image_from_db; 

it possible there mysql native function updating when null - i've heard of coalesce don't know how use - simplest way it.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -