0

I'm still new on php. I'm currently building a website which a user can upload an image to change their profile picture.

The file of image will we insert into table user, row image location on database and directory "upload". The formatting is like abc.jpeg

My code for the <img> tag, which is where I display the profile image. But the image does not appear. Only the thumbnail image is displayed and not the exact image.

<img src=<?php 
    $current = $fgmembersite->UserEmail();
    if ($handle = opendir('upload/')) {
        $sql = "SELECT image_location FROM user WHERE email='$current'";
        //$file = mysql_real_escape_string($sql);
        if ((file_exists('upload/'.$sql) == $sql)) {
            echo 'upload/'.$sql.'.png';
        } else if (file_exists('upload/'.$sql)) {
            echo 'upload/'.$sql.'.jpg';
        }
    }
    closedir($handle);
?> alt="">

If you don't mind, can you check my code and see where I went wrong? Thank you for your helping.

Tigger
  • 8,980
  • 5
  • 36
  • 40
Izzati
  • 35
  • 7
  • did you get the result correctly from the sql query? – laiju Dec 06 '17 at 04:56
  • @laiju yes. I have check my sql query and it doesn't show any error. – Izzati Dec 06 '17 at 05:01
  • 2
    i don't see the code where you execute the sql query. Please add the code to execute your sql query https://www.w3schools.com/php/php_mysql_select.asp – laiju Dec 06 '17 at 05:04
  • While @laiju is correct in pointing out an issue with your SQL, please use the [PHP Manual](http://php.net/manual/en/book.mysqli.php) instead of the w3school one. – Tigger Dec 06 '17 at 05:13
  • @laiju Thankyou for your helping. Now I can change my profile picture, – Izzati Dec 07 '17 at 07:28

0 Answers0