Jump to content

multi image update if form field not empty


nbbcj

Recommended Posts

hi all

 

i have a problem here,

 

Iv got a form  that uploads images to a folder and updates the db with the name of that image, that work ok

 

but if one of the upload field are left blank then the script updates the db with empty values

how can i get it to only update the db with only submitted form field data????

 

here is the form

<?php

if (isset($_GET['id'])) {
$id = $_GET['id'];
}

?>

<form action="ud_image.php?id=<? echo "$id"?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table class="udp">
  <tr>
    <th>Thumbnail:</th>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
  <tr>
    <th>Image 1:</th>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
  </tr>
  <tr>
    <th>Image 2:</th>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
  </tr>
  <tr>
    <th>Image 3:</th>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
  </tr>
  <tr>
    <th>Image 4:</th>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
<input name="ufile[]" type="file" id="ufile[]" size="50" /><input type="submit" name="Submit" value="Upload" /></td>
  </tr>
</table>
</form>

 

 

 

and here is the

 

processing page

 

<?php
include("protect/password_protect.php");

error_reporting(E_ALL);

include ("../includes/db_config.php");

$con = mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_database) or die( "Unable to select database");


$path1= "../thumbnails/".$_FILES['ufile']['name'][0];
$path2= "../images/".$_FILES['ufile']['name'][1];
$path3= "../images/".$_FILES['ufile']['name'][2];
$path4= "../images/".$_FILES['ufile']['name'][3];
$path5= "../images/".$_FILES['ufile']['name'][4];

//copy file to where you want to store file
copy($_FILES['ufile']['tmp_name'][0], $path1);
copy($_FILES['ufile']['tmp_name'][1], $path2);
copy($_FILES['ufile']['tmp_name'][2], $path3);
copy($_FILES['ufile']['tmp_name'][3], $path4);
copy($_FILES['ufile']['tmp_name'][4], $path5);
?>

<html>

<head>
<title>Update Project Images</title>
<link rel="stylesheet" type="text/css" href="../../project/backend/style.css" />
</head>
<body>
<table class="udip">
  <tr>
    <th><? echo "<img src=\"$path1\" width=\"150\" height=\"150\">";?></th>
    <th><? echo "<img src=\"$path2\" width=\"150\" height=\"150\">";?></th>
    <th><? echo "<img src=\"$path3\" width=\"150\" height=\"150\">";?></th>
    <th><? echo "<img src=\"$path4\" width=\"150\" height=\"150\">";?></th>
    <th><? echo "<img src=\"$path5\" width=\"150\" height=\"150\">";?></th>
  </tr>
  <tr>
    <td><? echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>";?></td>
    <td><? echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>";?></td>
    <td><? echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>";?></td>
    <td><? echo "File Name :".$_FILES['ufile']['name'][3]."<BR/>";?></td>
    <td><? echo "File Name :".$_FILES['ufile']['name'][4]."<BR/>";?></td>
  </tr>
  <tr>
    <td><?echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>";?></td>
    <td><?echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>";?></td>
    <td><?echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>";?></td>
    <td><?echo "File Size :".$_FILES['ufile']['size'][3]."<BR/>";?></td>
    <td><?echo "File Size :".$_FILES['ufile']['size'][4]."<BR/>";?></td>
  </tr>
  <tr>
    <td><? echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>";?></td>
    <td><? echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>";?></td>
    <td><? echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>";?></td>
    <td><? echo "File Type :".$_FILES['ufile']['type'][3]."<BR/>";?></td>
    <td><? echo "File Type :".$_FILES['ufile']['type'][4]."<BR/>";?></td>
  </tr>
</table>
</body>
</html>
<?
$filesize1=$_FILES['ufile']['size'][0];
$filesize2=$_FILES['ufile']['size'][1];
$filesize3=$_FILES['ufile']['size'][2];
$filesize4=$_FILES['ufile']['size'][3];
$filesize5=$_FILES['ufile']['size'][4];

if($filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 != 0)

{
echo "We have recieved your files<p>";
}

else {
echo "Error in you images check and try again Database has been updated to blank images so no images will be shown on details page.";
}


$query = "UPDATE $db_table SET 
thumbnail = '".$_FILES['ufile']['name'][0]."', image1 = '".$_FILES['ufile']['name'][1]."', image2 = '".$_FILES['ufile']['name'][2]."', image3 = '".$_FILES['ufile']['name'][3]."', image4 = '".$_FILES['ufile']['name'][4]."' WHERE id = '".$_GET['id']."'";


if (!mysql_query($query,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)


?>

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.