0

I am trying to upload images into my database table called tbl_images and to my images folder saved in the same folder as my source files! i am receiving the error "Parse error: syntax error, unexpected '$imagename' (T_VARIABLE) in"

Here is my index.php code

<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<form action="saveimage.php" method="post" enctype="multipart/form-data">
<h2>Please click on Upload button</h2>
<input type="file" name="uploadedimage">
<input type="submit" name="Upload Image" value="Upload Image">

</form>
</body>
</html> 

Here is saveimage.php file. Not sure what the problem is here. Any help is appreciated.

<?php

include ("connection.php");
function GetImageExtension($imagetype)
{
    if(empty($imagetype)) return false;
    switch($imagetype)
    {
        case 'image/bmp':return '.bmp';
        case 'image/gif':return '.gif';
        case 'image/png':return '.png';
        case 'image/jpeg':return '.jpeg';
        default: return false;
    }
}
if(!empty($_FILES["uploadedimage"]["name"]))
{
    $file_name=$_FILES["uploadedimage"]["name"];
    $temp_name=$_FILES["uploadedimage"]["tmp_name"];
    $imgtype=$_FILES["uploadedimage"]["type"];
    $ext=GetImageExtension($imgtype)
    $imagename=date("d-m-Y")."-".time().$.$ext;
    $target_path="images/".$imagename;

    if(move_uploaded_file($temp_name, $target_path))
    {
        $query_upload="INSERT into tbl_images 
        (image_name,submission_date) 
        values 
        ('".$imagename."','".date("Y-m-d")."')";
        mysqli_query($con,$query_upload);
            echo "Image has been uploaded";
        }
    }
    else {
        echo "Can not upload image";
    }
?>
  • Missing semicolon at end of line `$ext=GetImageExtension($imgtype)` – Enstage Apr 28 '17 at 01:40
  • Thanks alot, I did miss that but this error has now appeared! Parse error: syntax error, unexpected '.', expecting variable (T_VARIABLE) or '{' or '$' in D:\home\students\2081\saveimage.php on line 22 (This is the same line as $imagename=date... – Catherine Apr 28 '17 at 01:43
  • `.$.` is on that line, which makes no sense, maybe you're looking for: `$imagename=date("d-m-Y")."-".time().$ext;` – Enstage Apr 28 '17 at 01:45
  • Yeah that error disappeared, thank you! but is there anything wrong with the end of it? I got this error Parse error: syntax error, unexpected 'else' (T_ELSE), expecting end of file – Catherine Apr 28 '17 at 01:47
  • Remove the `}` immediately below the line `echo "Image has been uploaded";`. You have one too many close brackets. – Enstage Apr 28 '17 at 01:49
  • Thanks so much its working!! :) – Catherine Apr 28 '17 at 02:12
  • Would anybody be able to help me pull the image from the database? Her is my code, its not giving any error buts also not showing the image! ` ` – Catherine Apr 29 '17 at 21:43

0 Answers0