Php warnings and SQL syntax error

Urgent help needed in solving these sql syntax errors and warning notices on how to upload an image file into a database Thank you… Below are my Html pages,Php Code and Database script…

PHP

Animal <?php if (isset($_POST["submit"])) {

$aname = $_POST[“aname”];
$adetails = $_POST[“adetails”];
$aphoto = addslashes (file_get_contents($_FILES[“aphoto”][“tmp_name”]));
$image = getimagesize($_FILES[“aphoto”][“tmp_name”]);//to know about image type etc//
$imgtype = $image[‘mime’];

$conn = mysql_connect (“localhost”, “rupert”, “” );
$db = mysql_select_db(“imagestore”,$conn);
if(!$db)
{
echo mysql_error();
}

$query = “INSERT INTO animaldata VALUES (’’, ‘$aname’, ‘$adetails’, ‘$aphoto’,’$imgtype)”;
mysql_query($query,$conn);
$results = mysql_query($query,$conn);
if( $results )
{
echo “Information Stored Successfully”;
}
else
{
echo mysql_error();
}

}
?>

HTML

Animal Information

 

Animal Information

Animal Name
Animal Description
Animal Photo

DATABASE

– phpMyAdmin SQL Dump
– version 3.5.2.2
http://www.phpmyadmin.net

– Host: 127.0.0.1
– Generation Time: Nov 11, 2014 at 09:29 AM
– Server version: 5.5.27
– PHP Version: 5.4.7

SET SQL_MODE=“NO_AUTO_VALUE_ON_ZERO”;
SET time_zone = “+00:00”;

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/
!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/
!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/
!40101 SET NAMES utf8 */;


– Database: imagestore



– Table structure for table animaldata

CREATE TABLE IF NOT EXISTS animaldata (
ano int(5) NOT NULL AUTO_INCREMENT,
aname varchar(200) NOT NULL,
adetails text NOT NULL,
aphoto blob NOT NULL,
aphototype varchar(200) NOT NULL,
PRIMARY KEY (ano)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=‘Aniamal Information Table’ AUTO_INCREMENT=1 ;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/
!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/
!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

AND THE CORRESPONDING ERRORS ARE AS FOLLOWS:

Warning: file_get_contents(): Filename cannot be empty in C:\xampp\htdocs\Databasefoto\storeinfo.php on line 15

Warning: getimagesize(): Filename cannot be empty in C:\xampp\htdocs\Databasefoto\storeinfo.php on line 16
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’)’ at line 1

Any help will be of great importance to me…

First things first, STOP using mysql and switch to mysqli or pdo instead - do it today!

Second, your query is wrong.
Thirdly, move the PHP above the HTML, you’ll thank me for that later 8)

I have uploaded a tutorial here on uploading images.
Give it a try and if you’re still stumped, come back and let me know.

Red :wink:

i have switched to mysqliso whats next guys
Please start helping

post up your new code for me to take a look through, I’ll see what’s going on for you.

Note: when posting code here use the ‘php’ button in the editor or wrap your code in BB tags [ php ] [ / php ] without the spaces. Makes it easier for us to read.

Red :wink:

[php]<?php
if (isset($_POST[“submit”]))
{

$aname = $_POST[“aname”];
$adetails = $_POST[“adetails”];
$aphoto = addslashes (file_get_contents($_FILES[“aphoto”][“tmp_name”]));
$image = getimagesize($_FILES[“aphoto”][“tmp_name”]);//to know about image type etc//
$imgtype = $image[‘mime’];

$conn = mysqli_connect (“localhost”, “rupert”, “” );
$db = mysqli_select_db(“imagestore”,$conn);
if(!$db)
{
echo mysqli_error();
}

$query = “INSERT INTO animaldata VALUES (’’, ‘$aname’, ‘$adetails’, ‘$aphoto’,’$imgtype)”;
mysqli_query($query,$conn);
$results = mysqli_query($query,$conn);
if( $results )
{
echo “Information Stored Successfully”;
}
else
{
echo mysqli_error();
}

}
?>[/php]

only putting an i on the end of everything doesn’t make your queries mysqli but i applaud you for trying :slight_smile: ;D
Have a read of mysqli and pdo you’ll see what changes are needed when changing from mysql to mysqli

Have a read of this regarding file uploads.

Sponsor our Newsletter | Privacy Policy | Terms of Service