Hi everyone,
I’m putting together a system for my client where he can input data into a database. The Data is of a business listing on the website and it needs to include images. So what I intend to do is store the image in a separate folder and input the name of the image into the database so that my listings page knows what image goes with what listing.
The problem I’m running into is this: I’ve created a page called Input a Listing, which is just an HTML form that my client will fill out with all the information about the business (text only). Then at the end of the php page that handles the information and inputs it into the database I have a small form for uploading the first image.
that code is as follows:
[php]echo “”;
echo “”;
echo “Main Picture: Max 500kb”;
echo “”;[/php]
You’ll notice that I have 2 hidden fields with their values set as variables I defined earlier on the page. These variables are the name of the company and the suburb it is in and the data comes from the previous form.
The php page that handles the image is as follows:
[php]$name=$_POST[‘name’];
$subsubarea=$_POST[‘subsubarea’];
mysql_select_db(“wtgsacoz_wthsa”, $con);
define (“MAX_SIZE”,“500”);
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return “”; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST[‘Submit’]))
{
$image=$_FILES[‘image’][‘name’];
if ($image)
{
$filename = stripslashes($_FILES[‘image’][‘name’]);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != “jpg”) && ($extension != “jpeg”) && ($extension != “png”) && ($extension != “gif”))
{
echo ‘Unknown extension!’;
$errors=1;
}
else
{
$size=filesize($_FILES[‘image’][‘tmp_name’]);
if ($size > MAX_SIZE*1024)
{
echo ‘You have exceeded the size limit!’;
$errors=1;
}
$image_name=time().’.’.$extension;
$newname=“images/”.$image_name;
$copied = copy($_FILES[‘image’][‘tmp_name’], $newname);
if (!$copied)
{
echo ‘
Copy unsuccessfull!
’;$errors=1;
}
}}}
if(isset($_POST[‘Submit’]) && !$errors)
{
echo “File Uploaded Successfully!”;
}
$sql = mysql_query(“UPDATE listings SET mainpct = $image_name WHERE name=’$name’ AND subsubarea=’$subsubarea’”);[/php]
The last query named $sql is the function I intend to use to update the listing that was just input into the database, but when I run this page I get the error “query is empty!”. Is that becuase it can’t find the WHERE variables $name and $subsubarea? I don’t understand why my code isn’t working…
Please Help.