0

Please do help what is wrong with my database code. whenever i click on my update it will update the data but not in the database so whenever i logout the data will be back to the original and not the edited one

define('DB_HOST', '127.0.0.1');
define('DB_NAME', 'phptutorial');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');

$connection = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);

if($_POST){
    $bio = $_POST['bio'];
    $fullname = $_POST['fullname'];
    $image = '';

    if(isset($_FILES['image'])){
        $errors= array();
        $file_name = $_FILES['image']['name'];
        $file_size =$_FILES['image']['size'];
        $file_tmp =$_FILES['image']['tmp_name'];
        $file_type=$_FILES['image']['type'];
        $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));

        $expensions= array("jpeg","jpg","png");

        if(in_array($file_ext,$expensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
        }

        if(empty($errors)){
            $image = "images/".$file_name;
            move_uploaded_file($file_tmp, $image);
            $_SESSION['profile']['photo'] = $image;
        }else{

        }
    }

    $connection->query("UPDATE users SET fullname = '{$fullname}', bio = '{$bio}', photo = '{$image}' WHERE id = {$_SESSION['profile']['id']}");

    $_SESSION['profile']['fullname'] = $fullname;
    $_SESSION['profile']['bio'] = $bio;

    header('Location: home.php');
}
Andy G
  • 19,232
  • 5
  • 47
  • 69

0 Answers0