The following script intends to upload 4 files and place the paths to each of thoses 4 files in MySQL
But, it only uploads 1 file, and it places the path to that one file into the fields intended for each of the 4 files. The result is that the one uploaded image is displayed 4 times on the display page.
http://www.ibtpartners.org/ccl/announce/news/crnt/ccl_news.php?I think I understand why this is happening, but I do not know how to fix it so that each of the 4 files is uploaded, and the paths to those 4 files are inserted into the path field (pic1, pic2, pic3, pic 4) for each respective file.
Grateful for advice that will fix this problem.
Here is the code:
<?php require_once('../../Connec
tions/CCL_
Prayer.php
'); ?>
<?php
mysql_select_db($database_
CCL_Prayer
, $CCL_Prayer);
$query_Recordset1 = "SELECT * FROM ccl_news ";
$Recordset1 = mysql_query($query_Records
et1, $CCL_Prayer) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Records
et1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1
);
function GetSQLValueString($theValu
e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STR
ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE
RY_STRING'
]);
}
?>
<?php
include ($_SERVER['DOCUMENT_ROOT']
."/ccl/ann
ounce/news
/upload/up
load_class
.php"); //classes is the map where the class file is stored (one above the root)
$max_size = 2400*2400; // the max. size for uploading
$my_upload = new file_upload;
$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT'].
"/ccl/anno
unce/news/
upload/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".jpg", ".png", ".gif"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_fil
ename = 100; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;
if(isset($_POST['Submit'])
) {
$my_upload->the_temp_file = $_FILES['upload']['tmp_nam
e'];
$my_upload->the_file = $_FILES['upload']['name'];
$my_upload->http_error = $_FILES['upload']['error']
;
$my_upload->replace = (isset($_POST['replace']))
? $_POST['replace'] : "n"; // because only a checked checkboxes is true
$my_upload->do_filename_ch
eck = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
$new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
if ($my_upload->upload($new_n
ame)) { // new name is an additional filename information, use this to rename the uploaded file
$full_path = $my_upload->upload_dir.$my
_upload->f
ile_copy;
$info = $my_upload->get_uploaded_f
ile_info($
full_path)
;
// Define text variables needed to create path for image retreival
$img_src = "<img src=\"/ccl/announce/news/u
pload/";
$hspace = "\" hspace=\"10\" vspace=\"5\" align=\"left\" border=1>";
// Isolate the filename into a variable, then concatenate 3 variables
// to create the needed path to retreive the image
$path = ($full_path);
$my_filename = basename($path);
$my_path_string = ($img_src.$my_filename.$hs
pace);
}
if ((isset($_POST["MM_insert"
])) && ($_POST["MM_insert"] == "form1")) {
//$insertSQL = sprintf("INSERT INTO ccl_news (title, sec1_head, sec1_text, pic1) VALUES (%s, %s, %s, %s)",
$insertSQL = sprintf("INSERT INTO ccl_news (title, sec1_head, sec1_text, pic1, sec2_head, sec2_text, pic2, sec3_head, sec3_text, pic3, sec4_head, sec4_text, pic4) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['
title'], "text"),
GetSQLValueString($_POST['
sec1_head'
], "text"),
GetSQLValueString($_POST['
sec1_text'
], "text"),
GetSQLValueString($my_path
_string, "text"),
//GetSQLValueString($_POST
['pic1'], "text"),
GetSQLValueString($_POST['
sec2_head'
], "text"),
GetSQLValueString($_POST['
sec2_text'
], "text"),
GetSQLValueString($my_path
_string, "text"),
//GetSQLValueString($_POST
['pic2'], "text"),
GetSQLValueString($_POST['
sec3_head'
], "text"),
GetSQLValueString($_POST['
sec3_text'
], "text"),
GetSQLValueString($my_path
_string, "text"),
//GetSQLValueString($_POST
['pic3'], "text"),
GetSQLValueString($_POST['
sec4_head'
], "text"),
GetSQLValueString($_POST['
sec4_text'
], "text"),
GetSQLValueString($my_path
_string, "text"));
//GetSQLValueString($_POST
['pic4'], "text"));
mysql_select_db($database_
CCL_Prayer
, $CCL_Prayer);
$Result1 = mysql_query($insertSQL, $CCL_Prayer) or die(mysql_error());
$insertGoTo = "crnt/ccl_news.php";
if (isset($_SERVER['QUERY_STR
ING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
@import url("../../CCS_Styles/ccl_
css.css");
body {
background-color: #D7C997;
}
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style1 {
font-size: 16px;
font-weight: bold;
color: #0000FF;
}
-->
</style></head>
<body>
<table width="855" align="center" class="thin_border">
<tr>
<td width="845" colspan="2"><img src="file:///E|/My%20Docum
ents/websi
tes/ccl/Ri
bbon/ribbo
n_new_0802
17.png" width="845" height="129" align="right"></td>
</tr>
<tr>
<td height="28" colspan="2"><div align="center" class="style1">Enter Newsletter Items </div></td>
</tr>
<tr>
<td colspan="2"><form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-da
ta" name="form1">
<table width="844">
<tr>
<td colspan="2">Main Title:
<input name="title" type="text" id="title" value="COVENANT CLASS NEWS AND UPDATES FOR SUNDAY " size="80"></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="422" valign="top"><strong>Secti
on 1 </strong></td>
<td width="410"> </td>
</tr>
<tr>
<td valign="top"><div align="left">Heading:<br>
<input name="sec1_head" type="text" id="sec1_head" size="65">
</div></td>
<td valign="top">Text:<br>
<textarea name="sec1_text" cols="46" id="sec1_text"></textarea>
</td>
</tr>
<tr>
<td height="59" valign="top"><div align="left">
Picture Upload: <br>
<input name="upload" type="file" id="upload" size="52">
<br>
</div></td>
<td valign="top"> </td>
</tr>
<tr>
<td height="16" valign="top"><div align="left"><strong>Secti
on 2</strong></div></td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">Heading:<br>
<input name="sec2_head" type="text" id="sec2_head" size="65"></td>
<td valign="top">Text:<br>
<textarea name="sec2_text" cols="46" id="sec2_text"></textarea>
</td>
</tr>
<tr>
<td height="61" valign="top">Picture Upload: <br>
<input name="upload2" type="file" id="upload2" size="52">
<br></td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top"><strong>Secti
on 3 </strong></td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top"><div align="left">Heading<br>
<input name="sec3_head" type="text" id="sec3_head" size="65">
</div></td>
<td valign="top">Text:<br>
<textarea name="sec3_text" cols="46" id="sec3_text"></textarea>
</td>
</tr>
<tr>
<td height="59" valign="top"><div align="left">
Picture Upload: <br>
<input name="upload3" type="file" id="upload3" size="52">
<br>
</div></td>
<td valign="top">Text:<br> </td>
</tr>
<tr>
<td height="16" valign="top"><strong>Secti
on 4 </strong></td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top"><div align="left">
Heading: <br>
<input name="sec4_head" type="text" id="sec4_head" size="65">
<br>
</div></td>
<td valign="top">Text:<br>
<textarea name="sec4_text" cols="46" id="sec4_text"></textarea>
</td>
</tr>
<tr>
<td height="47" valign="top">Picture Upload:<br>
<input name="upload4" type="file" id="upload4" size="52"> </td>
<td valign="top"> </td>
</tr>
<tr valign="bottom">
<td height="33" colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($Records
et1);
?>