My code uploads to first image but the remaining four images return an error which reads "unidentified index name2" and repeats the same error for name3.4&5...
I sought the help of some tutorials but most if not all only allowed for uploading one image where as I'd like to upload five images into the same row...
here's the code
<?php
//The following code is the PHP form handling application.
//Connecting to the MySQL database
require('dbconnect.php');
if (isset ($_POST['postarticle'])){
//Simplifying the variables.
$name = isset($_POST['name']) ? $_POST['name'] : NULL;
$type = isset($_POST['type']) ? $_POST['type'] : NULL;
$description = isset($_POST['description']) ? $_POST['description'] : NULL;
$content = isset($_POST['content']) ? $_POST['content'] : NULL;
$content = mysql_real_escape_string($content);
$description = mysql_real_escape_string($description);
// Check to see if the type of file uploaded is a valid image type
function is_valid_type($file)
{
// This is an array that holds all the valid image MIME types
$valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif");
if (in_array($file['type'], $valid_types))
return 1;
return 0;
}
// Just a short function that prints out the contents of an array in a manner that's easy to read
// I used this function during debugging but it serves no purpose at run time for this example
function showContents($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
}
// This variable is the path to the image folder where all the images are going to be stored
// Note that there is a trailing forward slash
$TARGET_PATH = "images/";
// Get our POSTed variables
$image = $_FILES['image'];
$image2 = $_FILES['image2'];
$image3 = $_FILES['image3'];
$image4 = $_FILES['image4'];
$image5 = $_FILES['image5'];
$image['name'] = mysql_real_escape_string($image['name']);
$image2['name2'] = mysql_real_escape_string($image['name2']);
$image3['name3'] = mysql_real_escape_string($image['name3']);
$image4['name4'] = mysql_real_escape_string($image['name4']);
$image5['name5'] = mysql_real_escape_string($image['name5']);
// Build our target path full string. This is where the file will be moved do
// i.e. images/picture.jpg
$TARGET_PATH .= $image['name'];
$TARGET_PATH .= $image['name2'];
$TARGET_PATH .= $image['name3'];
$TARGET_PATH .= $image['name4'];
$TARGET_PATH .= $image['name5'];
//Checks for empty fields or invalid date.
if(is_null($name) || is_null($content) || is_null($type) || is_null($description)){
echo "All fields must be fill!";
}else{
if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))
{
//The MySQL query which will insert content into the table.
$query = "INSERT INTO `eyecandy` (`eid` ,`name` ,`description` ,`content` ,`image1` ,`image2` ,`image3`,`image4`,`image5`,`type`) VALUES ('', '$name', '$description', '$content', '$image[name]','$image2[name2]','$image3[name3]','$image4[name4]','$image5[name5]','$type')";
//Executing the query with mysql_query().
mysql_query($query) or die(mysql_error());
echo "<center><strong>New Entry added!!!</strong></center>";
}
}
}
//Closing the connection.
mysql_close($conn);
?>
<br />
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table align="center">
<tr>
<td align="right">Name:</td>
<td><input type="text" name="name" maxlength="250" size="90"/></td></tr>
<tr>
<td align="right">Short Description:</td>
<td><input type="text" name="description" maxlength="140" size="90"/></td></tr>
<tr>
<td align="right">Type:</td><td><select name="type" size="2">
<option>Eyecandy</option>
<option>Studs</option>
</select></td>
</tr>
<tr>
<td align="right">Content:</td>
<td><textarea name="content" cols="50" rows="10"></textarea></td>
</tr>
<tr>
<td align="right">Main Image:</td><td>
<input type="file" name="image" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
</td></tr>
<tr>
<td align="right">Image2:</td>
<td>
<input type="file" name="image2" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
</td></tr>
<tr>
<td align="right">Image3:</td>
<td>
<input type="file" name="image3" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
</td></tr>
<tr>
<td align="right">Image4:</td>
<td>
<input type="file" name="image4" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
</td></tr>
<tr>
<td align="right">Image5:</td>
<td>
<input type="file" name="image5" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
</td></tr>
<tr><td> </td><td><input type="submit" name="postarticle" value="Enter New Entry" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form></div></td>
</tr>
<tr>
<td id="contentbottom"><div style="color:#FFFFFF; margin-left:10px;">iLevel EntertainmentiLevel EntertainmentiLevel EntertainmentiLevel EntertainmentiLevel Entertainment</div></td>
</tr>
</table>
also I should state that I have no clue as to what to do
any help will be useful!
thanks in advance

New Topic/Question
Reply




MultiQuote



|