Jump to content

Recommended Posts

Hello there. I have a problem with inserting a name of the pictures in my table. My table have just 3 fields: id, photo & name.

 

This is html code:

 

 

<form action="nextpage.php" method="post" enctype="multipart/form-data">

<table>
<tr>
<td valign="top">Upload Image: </td>

<td>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo1" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo2" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo3" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo4" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo5" type="file" size="30"></td>
</tr>
<tr>
<td>
<input type="submit" value="Add" value="Wide button"></td>
</tr>
</table>
</form>

 

This is all php code:

 

<?php
$photo0=($_FILES['photo']['name']);
$photo1=($_FILES['photo1']['name']);
$photo2=($_FILES['photo2']['name']);
$photo3=($_FILES['photo3']['name']);
$photo4=($_FILES['photo4']['name']);
$photo5=($_FILES['photo5']['name']);
//This is the directory where images will be saved
$target = "images/upload/";
$targetx = $target . basename( $_FILES['photo']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo1']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo1']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo2']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo2']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo3']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo3']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo4']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo4']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo5']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo5']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
include "phpscripts/connect_to_mysql.php";
foreach(array($photo0, $photo1, $photo2, $photo3, $photo4, $photo5) as $value){
$sql="INSERT INTO `images` (`photo`,`name`) VALUES('".$value."', 'spain')";
}
$result=mysql_query($sql);

 

 

I think i have a problem in this fews lines:

 

 

 

foreach(array($photo0, $photo1, $photo2, $photo3, $photo4, $photo5) as $value){
$sql="INSERT INTO `images` (`photo`,`name`) VALUES('".$value."', 'spain')";
}

 

Also if it s possible to stop to do not upload if the user doesn't choose a files.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/268847-php-multiply-images-uploading/
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.