TaneskiIle Posted September 27, 2012 Share Posted September 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268847-php-multiply-images-uploading/ Share on other sites More sharing options...
trq Posted September 27, 2012 Share Posted September 27, 2012 You might want to tell us what the *problem* actually is. Quote Link to comment https://forums.phpfreaks.com/topic/268847-php-multiply-images-uploading/#findComment-1381284 Share on other sites More sharing options...
White_Lily Posted September 27, 2012 Share Posted September 27, 2012 Try changing $target = "path"; to $target = $_SERVER["DOCUMENT_ROOT"]."path"; Quote Link to comment https://forums.phpfreaks.com/topic/268847-php-multiply-images-uploading/#findComment-1381413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.