Jump to content

last row overwriting the previous row in the table.


erok
Go to solution Solved by tryingtolearn,

Recommended Posts

Hi all ,

 

I am trying to write some codes which needs to be able to upload multiple images into separate rows in a table  within one form.

 

i only got the last picture inserted twice to mysqli database table, instead of inserting the first picture in the form first and moving to the second picture next.

Any direction or help greatly appreciated.

 

My code like this ;

 

if (!empty($_POST['kitchen']))
   {                                                                       
//Assign Variables
$path = $_FILES['image']['tmp_name'] ;
$name = $_FILES['image']['name'] ;
$type = $_FILES['image']['type'] ;
$error= $_FILES['image']['error'] ;
$caption = $_POST['caption'] ;            
 
// read file contents
$content2 = file_get_contents($path);
$content = mysqli_real_escape_string($con, $content2);
$caption = mysqli_real_escape_string($con, $caption) ;
$bol = "insert into dakimages (name, type, content, caption) values ('{$name}', '{$type}', '{$content}', '{$caption}');";
$soy = mysqli_query($con, $bol) ;
 }
if (!empty($_POST['kitchen']))
   {                                                                      
//Assign Variables
$path = $_FILES['image']['tmp_name'] ;
$name = $_FILES['image']['name'] ;
$type = $_FILES['image']['type'] ;
$error= $_FILES['image']['error'] ;
$caption = $_POST['caption'] ;
          
// read file contents
$content2 = file_get_contents($path);
$content = mysqli_real_escape_string($con, $content2);
$caption = mysqli_real_escape_string($con, $caption) ;
                
 // insert into table
      $dor = "insert into dakimages (name, type, content, caption) values ('{$name}', '{$type}', '{$content}', '{$caption}');";
      $scl = mysqli_query($con, $dor) ;
    }
?>
And this is form ;
 
<input type="file" name="image" />
<br />
<br />
<span class="margin1">Caption for photo (1)</span>
<br />
<textarea type="text" name="caption" maxlength="150"  rows="3" col="85"></textarea>
<br />
<input type="file" name="image" />
<br />
<span class="margin1">Caption for photo (2)</span>
<br />
<textarea type="text" name="caption" maxlength="150"  rows="3" col="85"></textarea>
<br />
<input type="submit" name="kitchen" id="forminsert" value="upload all" size="35" />
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.