on return ,says success on image upload, but values(image) not updated neither in db-table row nor in folder in pdo
my code is as below: dbconfig.php (this file is includes inside class.user.php
<?php
class Database
{
private $host = "localhost";
private $user = "root";
private $pw= "pw";
private $db= "db";
public $conn;
public function dbConnection()
{
$this->conn = null;
try
{
$this->conn = new PDO("mysql:host=" . $this->host . ";db=" . $this->db, $this->user, $this->pw);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>
myprofile.php page (I want to update only one image field (location)).
<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();
if(!$user_home->is_logged_in())
{
$user_home->redirect('index.php');
}
$stmt = $user_home->runQuery("select * from tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
?>
<?php echo $row['firstName']?> <?php echo $row['lastName']; ?>
<?php echo $row['userEmail']; ?>
<div align="center"><img src="uploads/<?php echo $row['location']; ?>" />
</div>
<form action="#" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="action" value="update" />
</form>
<?php
$connectionClass = new Database();
$conn = $connectionClass->dbConnection();
$action = isset( $_POST['action'] ) ? $_POST['action'] : "";
if($action == "update"){
try{
$uid = $_SESSION['userSession'];
move_uploaded_file($_FILES['location']['tmp_name'], "uploads/" . $_FILES['location']['name']);
$path = $_FILES['location']['name'];
$query = 'update tbl_users set location = :location WHERE userID=:uid';
$stmt = $conn->prepare($query);
$stmt->bindParam(':location', $location, PDO::PARAM_STR);
$stmt->bindParam(':uid', $uid, PDO::PARAM_INT);
$stmt->execute();
echo "Sucesss.....";
}catch(PDOException $exception){
echo "Error: " . $exception->getMessage();
}
} ?>