Recently I found a way to upload an image path into a MySQL db while uploading the actual image to the server.
This works fine, except sometimes I don't have an image to upload with the story. So - my question:
If I don't have an image how do I get this script to fill automatically the path to the image on the server "NoPicture.jpg".
Here is the current script I'm using:
<?php
$uploadDir = '/server/location/uploads';
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileName2 = $_FILES['userfile2']['name'];
$tmpName2 = $_FILES['userfile2']['tmp_name'];
$fileSize2 = $_FILES['userfile2']['size'];
$fileType2 = $_FILES['userfile2']['type'];
$filePath = $uploadDir . $fileName;
$filePath2 = $uploadDir . $fileName2;
$result = move_uploaded_file($tmpName, $filePath);
$result = move_uploaded_file($tmpName2, $filePath2);
if (!$result) {
echo "Error uploading file";
exit;
}
include ("db_connect.inc");
$nwcomments = htmlspecialchars ($_POST[comments], ENT_QUOTES);
$nwpastwrain = htmlspecialchars ($_POST[pastwrain], ENT_QUOTES);
$nwtemp = htmlspecialchars ($_POST[temp], ENT_QUOTES);
$nwcp = htmlspecialchars ($_POST[cp], ENT_QUOTES);
$nwccs = htmlspecialchars ($_POST[ccs], ENT_QUOTES);
$nwccyp = htmlspecialchars ($_POST[ccyp], ENT_QUOTES);
$nwccp = htmlspecialchars ($_POST[ccp], ENT_QUOTES);
$nwcfp = htmlspecialchars ($_POST[cfp], ENT_QUOTES);
$nwcpwt = htmlspecialchars ($_POST[cpwt], ENT_QUOTES);
$nwsbcs = htmlspecialchars ($_POST[sbcs], ENT_QUOTES);
$nwsbcyp = htmlspecialchars ($_POST[sbcyp], ENT_QUOTES);
$nwsbcp = htmlspecialchars ($_POST[sbcp], ENT_QUOTES);
$nwsbfp = htmlspecialchars ($_POST[sbfp], ENT_QUOTES);
$nwsbpwt = htmlspecialchars ($_POST[sbpwt], ENT_QUOTES);
$nwsoilmoist = htmlspecialchars ($_POST[soilmoist], ENT_QUOTES);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
$fileName2 = addslashes($fileName2);
$filePath2 = addslashes($filePath2);
}
$query = "INSERT INTO northeast_conditions (cpicname, cpicsize, cpictype, cpicpath, sbpicname, sbpicsize, sbpictype, sbpicpath, date, pastwrain, soilmoist, temp, cp, ccs, ccyp, ccp, cfp, cpwt, sbcs, sbcyp, sbcp, sbfp, sbpwt, comments ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$fileName2', '$fileSize2', '$fileType2', '$filePath2', '$_POST[date]', '$nwpastwrain', '$nwsoilmoist', '$nwtemp', '$nwcp', '$nwccs', '$nwccyp', '$nwccp', '$nwcfp', '$nwcpwt', '$nwsbcs', '$nwsbcyp', '$nwsbcp', '$nwsbfp', '$nwsbpwt', '$nwcomments')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
echo "<br><a href='northeast_conditions.php'>View Updated Page</a><br>";
}
?>
Thanks for even looking at this!
Seth