Greetings fellow Guru's. It is me once again! The "Shade Tree Web Designer".
I have another good one here. What I am trying do is insert data into a database AND upload a file at the same time. I know how to do one, and the other, just not both put together.
The script that I have below does not have ANY of the ftp upload stuff because I am not exactly sure how to go about this. I do have the "file upload" form box in the form. I just dont know how to get it to upload when the user presses submit. I do have the info going into the DB, just need help with the uploading part. Here is the code:
//connection
$host = "";
$user = "_web";
$pass = "";
$database = "";
$tablename = "photo";
if($_POST['submit'] == null)
{
echo'
<html>
<head>
<title>Update</title>
</head>
<body>
<form method="post" action="'.$PHP_SELF.'">
<p align="left"><b>*Picture Title:</b>
<input type="Text" name="pictitle"> (What do you want the title of the picture to be?)
<br>
<b>*Picture Name: </b>
<input type="Text" name="picname"> (This must be the EXACT name of the file to be uploaded!)
<br>
<b>Submitted By: </b>
<input type="Text" name="submitby"> (This is not required, but some of us would like to know who submitted the picture)
<br>
<b>File to upload: </b>
<input type=file name="pic">
<br>
<b> Comments: (HTML OK)<br></b>
<textarea mmTranslatedValueHiliteColor="HILITECOLOR=%22No Color%22" mmTranslatedValueHiliteColor="HILITECOLOR=%22No Color%22" mmTranslatedValueHiliteColor="HILITECOLOR=%22No Color%22" mmTranslatedValueHiliteColor="HILITECOLOR=%22No Color%22" mmTranslatedValueHiliteColor="HILITECOLOR=%22No Color%22" mmTranslatedValueHiliteColor="HILITECOLOR=%22No Color%22" mmTranslatedValueHiliteColor="HILITECOLOR=%22No Color%22" name="comment" cols="75" rows="10"></textarea>
</p>
<p>
<input type="Submit" name="submit" value="Submit!">
</p>
</form>
* = required fields
</body>
</html>';
}else{
//check to make sure all required fileds have data in them.
Global $_POST;
$i = "0";
if($_POST['pictitle'] == null)
{
$errmsg = "Picture Title Field is empty<br>"; $i++;
}
if($_POST['picname'] == null)
{
$errmsg .= "Picture Name field is empty<br>"; $i++;
}
if($i > "0")
{
exit($i." <BR><BR><BR><B>Errors have occured. Please press the back button on your browser and
enter all the required data:<BR><br></B>".$errmsg);
}
//insert data into DB
$sql = "INSERT INTO `".$tablename."`
(picname,pictitle,submitby,comment,date)
VALUES (
'".$_POST['picname']."',
'".$_POST['pictitle']."',
'".$_POST['submitby']."',
'".$_POST['comment']."',
NOW( )
)";
$conn = @mysql_connect($host, $user, $pass)
or die("Could not Connect to MySQL:<br><b>".mysql_errno().":</b> ".mysql_error());
$db = mysql_select_db($database);
$the_query = @mysql_query($sql)
or die("Could not Execute MySQL Query:<br>".$sql."<br><br><b>".mysql_errno().":</b> ".mysql_error());
if(mysql_error() == null)
{
echo("<BR><BR><BR>Thank you ".$_POST['submitby']." for your pics!
<BR>
Thank you,<BR>
Staff at Middlemagick");
//email alert
$adminaddr1="";
$adminaddr2="";
$id = mysql_insert_id();
//mail admin 1
mail($adminaddr1, 'Feedback has been posted!',
"Greetings Webmaster,
A user has submitted and posted pics to our website. Please refer to record number $id for more details.
Thank you,
Systems ");
//mail admin 2
mail($adminaddr2, 'Feedback has been posted!',
"Greetings Mary,
A user has submitted pics to your website. Please refer to record number $id for more details. Please go to the phpMyAdmin
control panel and log in.
Thank you,
Systems ");
}else{
echo("<br><br>Errors have occured");
}
mysql_close($conn);
}
Thanks in advance for your help,
Todd