2011-12-25, 12:14 PM
Hey, trying to image uploading for a part of my site.
I'm getting this error:
Parse error: syntax error, unexpected T_ELSE in MYROOT/index.php on line 37
This is my code here: This is the index.php where I'm getting the error.
This is my get.php:
All my code does is upload a picture store it in my database for later use.
Don't know how to fix it, so please help!
Thanks Onz
I'm getting this error:
Parse error: syntax error, unexpected T_ELSE in MYROOT/index.php on line 37
This is my code here: This is the index.php where I'm getting the error.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Upload an image.</title>
</head>
<body>
<form action="index.php" method="POST" enctype="multipart/form-data">
File:
<input type="file" name="image"> <input type="submit" value="Upload">
</form>
<?php
// connect to database
mysql_connect("localhost","USER!","PASSWORD!") or die(mysql_error());
mysql_select_db("DB HERE!") or die(mysql_error());
// file properties
$file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo "Please select an image.";
else
{
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size==FALSE)
echo "That's not an image.";
else
{
if (!$insert = mysql_query("INSERT INTO store VALUES('','$image_name','$image')"));
echo "Problem uploading image.";
else // Line 37 is here!
{
$lastid = mysql_insert_id();
echo "Image upload.<p />Your image:<p /><img src=get.php?id$lastid>";
}
}
}
?>
</body>
</html>
This is my get.php:
<?php
// connect to database
mysql_connect("localhost","USER!","PASSWORD!") or die(mysql_error());
mysql_select_db("DB HERE!") or die(mysql_error());
$id = addslashes($_REQUEST['id']);
$image = mysql_query("SELECT * FROM store WHERE id=$id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;
?>
All my code does is upload a picture store it in my database for later use.
Don't know how to fix it, so please help!
Thanks Onz