I found this code on the net that lets me upload multiple images at once. Now I have no problem getting the files into the destination but I cant seem to be able to store the name in my db. I have created a db table with 8 colums (id, title, date, txt, picture1, picture2, picture3, picture4).
Now if you look at my code you may be asking yourself what the hell is that unorganized code, but since I am a begginer at PHP and I tried modifying it to the best of my knowledge which is why I am here asking you how to fix this problem.
Here is my code:
- Code: Select all
<?PHP
include("func.php");
if ($_GET['option']) {
switch ($_GET['option']) {
case "upload":
echo "<form method=post action='upload.php?option=process' enctype='multipart/form-data'>\n
<a class=txt><li> Title</a><br>
<input type=text name=title>
<textarea cols=55 rows=10 name=txt size=24 wrap=VIRTUAL></textarea><br>
*<b>File:</b><br><small>(max file size 4 meg and .zip file format only)</small>\n
<input type=file name='userfile1' size=50><br><br>\n
*<b>File:</b><br><small>(max file size 4 meg and .zip file format only)</small>\n
<input type=file name='userfile2' size=50><br><br>\n
*<b>File:</b><br><small>(max file size 4 meg and .zip file format only)</small>\n
<input type=file name='userfile3' size=50><br><br>\n
*<b>File:</b><br><small>(max file size 4 meg and .zip file format only)</small>\n
<input type=file name='userfile4' size=50><br><br>\n
<input type=hidden name=assume value=true>
<input type=submit name='submit' value='Submit File'>\n
<br><br>Only hit Submit File once and wait for file to upload.\n
</form>\n";
break;
case "process":
$assume = $_POST['assume'];
$txt = $_POST['txt'];
$title = $_POST['title'];
if ($assume == "true") {
$iCount = 1;
while ($iCount != 5){
$stFile = "userfile" . $iCount;
if ($_FILES[$stFile]['tmp_name'] != '') {
if (copy($_FILES[$stFile]['tmp_name'], "newsimgs/" . $_FILES[$stFile]['name'])) {
$userfile_location = "newsimgs/";
unlink($_FILES[$stFile]['tmp_name']);
}
}
$iCount = $iCount + 1;
}
$picture1 = $_POST['$stFile'];
$picture2 = $_POST['$stFile'];
$picture3 = $_POST['$stFile'];
$picture4 = $_POST['$stFile'];
$dbcnx = mysql_connect("localhost", "username", "password");
mysql_select_db("comments");
$sql = "INSERT INTO pgwrldnews SET txt='$txt', title='$title', picture1='$picture1', picture2='$picture2', picture3='$picture3', picture4='$picture4'";
if (mysql_query($sql)) {
echo("Your comment has been added");
} else {
echo("Error adding entry: " . mysql_error() . "");
}
}
}
} else {
echo "Click <a href='upload.php?option=upload'>Upload</a> to test this program.<br><br>";
}
?>
Any help would be greatly apreciated, thanks.
Nick




