1

i just need help regarding my code becuase i odnt have any idea where is the syntax error.

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

if (!isset($file)) 
   echo "Please select an image";
else
{
   $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
   $img_name = addslashes($_FILES['image']['name']);
   $img_size = getimagesize($_FILES['image']['tmp_name']);
   if ($img_size == FALSE) 
      echo "select valid image.";
   else
   {
      if (!$insert = mysql_query("insert into testblob values('','$image','$img_name')"));
         echo "Problem uploading!";
      else
      {
         $lastid = mysql_insert_id();
         echo "Image uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
      }
   }
}

i just need to know where is the error. thnaks for the help. more power ..

4
  • Which line PHP reports you? Commented Mar 21, 2014 at 15:25
  • Indenting your code may make the solution obvious. Commented Mar 21, 2014 at 15:25
  • 4
    i know its possible to do if..else without curly braces, but you really should just always use curly braces even if its only one line... Commented Mar 21, 2014 at 15:27
  • also, if (!$insert=mysql_query("insert into testblob values('','$image','$img_name')")); should not have a ; at the end.. Commented Mar 21, 2014 at 15:27

3 Answers 3

2

You have a semi-colon ; in your conditional statement extra here:

if (!$insert=mysql_query("insert into testblob values('','$image','$img_name')"));

Remove it and change it to:

if (!$insert=mysql_query("insert into testblob values('','$image','$img_name')"))

why dont you use this better ?

   $file= $_FILES['image']['tmp_name'];
   if (!isset($file)){
      echo "Please select an image";
     }
   else{
        $image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
        $img_name= addslashes($_FILES['image']['name']);
        $img_size = getimagesize($_FILES['image']['tmp_name']);

       if ($img_size==FALSE){
             echo "select valid image.";
              }
       else
         {

              if (!$insert=mysql_query("insert into testblob values('','$image','$img_name')")){
                   echo "Problem uploading!"; }
              else{

                $lastid = mysql_insert_id();
                    echo "Image uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
                }

        }
 }
Sign up to request clarification or add additional context in comments.

Comments

1

I intended the code and added some more braces which makes it a lot easier to see an error. I also deleted a semicolon (;) after one of the if clauses which probably caused the error.

if (!isset($file)) {
    echo "Please select an image";
}
else {
    $image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $img_name= addslashes($_FILES['image']['name']);
    $img_size = getimagesize($_FILES['image']['tmp_name']);

    if ($img_size==FALSE) {
        echo "select valid image.";
    }
    else {
        if (!$insert=mysql_query("insert into testblob values('','$image','$img_name')")) /* HERE WAS A SEMICOLON */ {
            echo "Problem uploading!";
        }
        else {
            $lastid = mysql_insert_id();
            echo "Image uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
        }

    }
}

Comments

1

This line

if (!$insert=mysql_query("insert into testblob values('','$image','$img_name')"));

has an unnecessary ; at the end of it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.