0
   <?php
    error_reporting(0);
    //connection
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "visionci";

    // Create connection
    $conn = new mysqli($servername, $username, $password,$dbname);

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 

    //file properties
    //if (isset($_POST['image']))  

     $file = $_FILES["image"]["tmp_name"];


    if (!isset($file))
         {//echo "Please Select an Image";
         }

    else
        {   $name = $_POST["name"];
            $rollno = $_POST["rollno"];
            $address = $_POST["address"];
            $duration = $_POST["duration"];
            $course=$_POST["course"];
            $fname = $_POST["fname"];
            $mname = $_POST["mname"];
            $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
            {
                $sql = "INSERT INTO insert (rollno,name,image,address,duration,fname,mname,course)VALUES('$rollno','$name','$image','$address','$duration','$fname','$mname','$course')";

                if ($conn->query($sql) === TRUE) 
                {
                    //$lastid= mysqli_insert_id($conn);
                    echo "Record Inserted Successfully!";
                } 
                else 
                {
                    echo "Error: " . $sql . "<br>" . $conn->error;
                }


            }
        }

Above is my code. I am getting some garbage value followed by an error [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 'insert (rollno,name,image,address,duration,fname,mname,course)VALUES('','','ÿØ' at line 1]

Let me know where I am getting problem I am Stuck.

  • It seems like you did not get `$address` via `POST`. Also, are you storing the image as a `BLOB`? – Aniket Dec 21 '14 at 05:39
  • `INSERT into INSERT`. Reserved keywords need to be quoted in backticks. And string values should furthermore be escaped. – mario Dec 21 '14 at 05:40

2 Answers2

0

Change your table name from insert. That can't be distinguished from the command insert, and you couldn't select from a table named insert without escaping

INSERT INTO something_else

or

INSERT INTO `insert`
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

$sql = "INSERT INTO insert (rollno,name,image,address,duration,fname,mname,course)VALUES('$rollno','$name','$image','$address','$duration','$fname','$mname','$course')";

Here you have used a "insert" as a table name. It is a Reserved key word in MySQL so change that name in to another value and try again.

Chamika Kasun
  • 96
  • 3
  • 16