hi! I badly need help on this one. I'm trying to upload images to a database using a looped form, where it will ask the user the number of images it needs to upload then insert it to my database. I used the following codes, but it's not working.
I used this for the looped form, where it will get the number of images that's needed to be uploaded:
<table width="60%" border="0" align="center" cellpadding="5" cellspacing="0">
<?php
for ($i = 0; $i < $_POST['num_images']; $i++){
// Determine alternate row colours
if($i % 2 == 0){
$style = "bgcolor=\"#FFFFFF\"";
$bottomstyle = "bgcolor=\"#FFFFFF\"";
} else {
$style = "bgcolor=\"#EFEFEF\"";
$bottomstyle = "bgcolor=\"#EFEFEF\"";
}
echo("\n<tr>\n<td $style width='15%'>Image #" . ($i + 1) . ": </td>\n<td $style><input type='file' name='image'></td>\n</tr>");
echo("\n<tr>\n<td $style width='15%'>Image Title : </td>\n<td $style><input type='text' name='photo_title'></td>\n</tr>");
echo("\n<tr>\n<td $style valign=\"top\">Photo Description: </td>\n<td $style><textarea name='photo_desc' cols='30' rows='6' wrap='default'></textarea></td>\n</tr>");
echo("\n<tr>\n<td $style valign=\"top\">Album Cover? </td>\n<td $style> <input type='radio' name='album_cover' value='$i'>");
}
echo("
<tr>
<td $style> </td>
<td $style>
<input name='process' type='hidden' value='1'>
<input name='album_id' type='hidden' value='" . $_POST['albums'] . "'>
<input name='submit' type='submit' id='submit' value='Continue'>
</td>
</tr>");
?>
</table>
</form>
</td>
</tr>
</table>
Heres the code for the inserting it to my database:
<?php
include("config.php");
$dbcnx = mysql_connect("localhost", "root", "root");
mysql_select_db("parctestdb", $dbcnx);
$sql = "INSERT INTO photos (photo_title, photo_desc) VALUES('$_POST[photo_title]','$_POST[photo_desc]')";
$result = mysql_query($sql, $dbcnx) or die("Error inserting record(s) into the database: " . mysql_error());
if ($result){
echo("Images successfully converted and stored! <br />Click <a href='../admin'>here</a> to continue.");
}
}
?>
Thanks!
uploading image from a looped form to a database
Moderator: General Moderators
-
agent007marc
- Forum Newbie
- Posts: 3
- Joined: Tue Sep 08, 2009 11:37 pm