Uploading Image to MySql database (1 Viewer)

RajaGautam

Registered User.
Local time
Today, 18:53
Joined
Apr 5, 2013
Messages
10
I have two php extension code one for form input & another for upload to MySql database management system. The form input code is as below:

denoted by "main.php"

<html>
<title>Animal Information</title>
<body>
<form enctype="multipart/form-data" action="storeinfo.php" method="POST">
<table border=0 align=center bgcolor=black width=100%>
<tr>
<td colspan=2><h2>&nbsp</h2></td>
</tr>
</table>
<table border=0 align=center bgcolor=grey>
<tr>
<td cospan=2><h2>Animal Information</h2></td>
</tr>
<tr>
<td>Animal Name</td><td><input type=text name="aname"></td>
</tr>
<tr>
<td>Animal Description</td><td><input type=text name="adetails"></td>
</tr>
<tr>
<td>Animal Photo</td><td><input type=file name="aphoto"></td>
</tr>
<tr>
<td></td><td><input type=submit name="submit" value="Store Information"></td>
</tr>
</table>
</form>
</body>
</html>

There is no error in this above code

The upload code is as below:

denoted by "storeinfo.php"

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysql_connect("localhost","root","");
if(!$conn)
{
echo mysql_error();
}
$db = mysql_select_db("imagestore",$conn);
if(!$db)
{
echo mysql_error();
}
$aname = $_POST['aname'];
$adetails = $_POST['adetails'];
$aphoto = addslahes(file_get_contents($_FILES['aphoto']['tmp_name']));
$image = getimagesize($_FILES['aphoto']['tmp_name"]);//to know about iamge type
$imgtype = $image['mime'];
$q="INSERT INTO animaldata VALUES('','$aname','$adetails','$aphoto','$imgtype')";
$r = mysql_query($q,$conn);
if($r)
{
echo "Information stored successfully";
}
else
{
echo mysql_error();
}
?>

When i fill up all Animal Information section and browse for image & click on summit button it display the error as below:

Parse error: syntax error, unexpected 'mime' (T_STRING), expecting ']' in C:\xampp\htdocs\php\storeinfo.php on line 18

line 18: $imgtype = $image['mime'];

The image file size is 34.8KB. I have managed my PhpMyAdmin database name databaseimage with proper data & validity entries.

My Php version is 5.4.7, SQL version is 5.5.27. Why 'mime' is unexpected ? Please help me to solve it. :)
 

plog

Banishment Pending
Local time
Today, 08:08
Joined
May 11, 2011
Messages
11,611
You mixed single quotes with double quotes in the line before:

$image = getimagesize($_FILES['aphoto']['tmp_name"]);//to know about iamge type


before tmp_name is a single quote, but after is a double. Try this:

$image = getimagesize($_FILES['aphoto']['tmp_name']);//to know about iamge type
 

RajaGautam

Registered User.
Local time
Today, 18:53
Joined
Apr 5, 2013
Messages
10
Hi! I fix single quotes with double quotes issue but even though it has an error saying:

Fatal error: Call to undefined function addslahes() in C:\xampp\htdocs\php\storeinfo.php on line 16


Line 16: $aphoto = addslahes(file_get_contents($_FILES['aphoto']['tmp_name']));

Why there is undefined function addslahes? Please help me to solve it?
 

weberbw

New member
Local time
Today, 09:08
Joined
Apr 25, 2013
Messages
1
Its addslashes not addslahes.

Add that extra s and you should be good!
 

preetisoft2

Registered User.
Local time
Today, 06:08
Joined
May 6, 2013
Messages
14
Thanks for sharing this. I was searching for that from a long time.
 

Users who are viewing this thread

Top Bottom