I am building a simple form that adds comments and image file names to a table in a database. The code is this:
<?PHP
include("function.php");
$name="My Name";
//The If and Switch direct people on the choices they make.
if ($option) {
switch ($option) {
case "upload":
require("header.php");
//This is your basic form
echo "<FORM METHOD=POST ACTION='upload.php?option=process' ENCTYPE='multipart/form-data'>\n
<B>*MLS ID:</B><BR>\n
<INPUT TYPE=TEXT NAME='Idf' SIZE=50 MAXLENGTH=50><BR><BR>\n
<INPUT TYPE=HIDDEN NAME='office_id' VALUE ='1'>\n
<B>Additional Comments about this listing</B><BR>\n
<INPUT TYPE=TEXT NAME='comments' SIZE=50 MAXLENGTH=500><BR><BR>\n
<B>Picture 1:</B><BR><SMALL>(max file size 4 megs)</SMALL><BR>\n
<INPUT TYPE=FILE NAME='picture' SIZE=50><BR><BR>\n
<B>Picture 2:</B><BR><SMALL>(max file size 4 megs)</SMALL><BR>\n
<INPUT TYPE=FILE NAME='picture2' VALUE=none SIZE=50><BR><BR>\n
<B>Picture 3:</B><BR><SMALL>(max file size 4 megs)</SMALL><BR>\n
<INPUT TYPE=FILE NAME='picture3' SIZE=50><BR><BR>\n
<B>Picture 4:</B><BR><SMALL>(max file size 4 megs)</SMALL><BR>\n
<INPUT TYPE=FILE NAME='picture4' SIZE=50><BR><BR>\n
<B>Picture 5:</B><BR><SMALL>(max file size 4 megs)</SMALL><BR>\n
<INPUT TYPE=FILE NAME='picture5' SIZE=50><BR><BR>\n
<B>Picture 6:</B><BR><SMALL>(max file size 4 megs)</SMALL><BR>\n
<INPUT TYPE=FILE NAME='picture6' SIZE=50><BR><BR>\n
* <FONT COLOR='#FF0000'>Signify Required Fields</FONT><BR><BR>\n
<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";
require("footer.php");
break;
case "process":
//This checks to make sure all the required fields are filled out
if (($Idf) && ($office_id)) {
//Trims Spaces off the strings
$Idf = trim($Idf);
$office_id = trim($office_id);
//Copies file to specified location
if (exec("mkdir /var/www/html/propimages/featured/$Idf"));
{}
if (copy($picture, "/var/www/html/propimages/featured/$Idf/$picture_name"))
{}
if (copy($picture2, "/var/www/html/propimages/featured/$Idf/$picture2_name"))
{
$userfile_location = "/var/www/html/propimages/featured/$Idf/";
//Deletes file in TMP directory
unlink($picture);
//Add File info to database
add_file($Idf, $office_id, $comments, $picture_location, $picture_name, $picture2_location, $picture2_name, $picture3_location, $picture3_name, $picture4_location, $picture4_name, $picture5_location, $picture5_name, $picture6_location, $picture6_name);
} else {
require("header.php");
echo "Your file could not be copied.\n";
require("footer.php");
}
} else {
require("header.php");
echo "You neglected to fill out all the required info<BR> please use the back button to fill in reqired
info.<BR><BR>\n";
echo "If you have reached this page in error please <A HREF='upload.php'>Click Here</A>.\n";
require("footer.php");
}
break;
case "confirm":
require("header.php");
echo "$name, your file was successfully uploaded!<BR><BR>\n";
echo "Thanks $name for your File submission<BR><BR>\n";
echo "From the staff at <B>RealESearch.Com</B><BR><BR>\n";
echo "Back <A HREF='upload.php'>Upload</A> page.<BR><BR>\n";
require("footer.php");
break;
default:
require("header.php");
echo "Please go back and select another page this one may be down.<BR><BR>\n
If the page still does not come up please contact us so we can correct the error.<BR><BR>\n
If you have reached this page in error <A HREF='upload.php'>Click Here</A>.\n";
require("footer.php");
break;
}
} else {
require("header.php");
echo "
This is the admin tool page<BR>
All features will show up on this page.<BR>
Click <A HREF='upload.php?option=upload'>Add/Edit Featured Listings</A><BR><BR>\n";
require("footer.php");
}
?>
It does a fair job but I have a few issues. Basically, I want to use this script to add info and update info already there...
1) My query (in function.php) looks like this:
$query = "REPLACE INTO $table_name (Idf, office_id, picture_name, picture2_name, picture3_name, picture4_name,
picture5_name, picture6_name, comments)
VALUES
('$Idf', '$office_id', '$picture_name', '$picture2_name', '$picture3_name', '$picture4_name', '$picture5_name',
'$picture6_name', '$comments')";
I have a feeling this is a majority of my problems. How exactly should this query be structured to I can add and update info in the table.
2) I also seem to have issues here in the script:
{}
if (copy($picture, "/var/www/html/propimages/featured/$Idf/$picture_name"))
{}
if (copy($picture2, "/var/www/html/propimages/featured/$Idf/$picture2_name"))
{
It works fine....but the script needs to have info in picture1 and picture2 or else it breaks.
Can anyone notice anything odd or ways I can improove these problems?