有誰知道爲什麼PHP代碼沒有更新列pictures
將更新他們的休息,但只是沒有圖片列是更新用戶信息,以便電子郵件地址,密碼和圖片我是很新的PHP,所以我真的不知道要尋找什麼,當即時尋找錯誤爲什麼心不是我的PHP代碼更新SQL
<?php
require("common.php");
if(empty($_SESSION['user']))
{
header("Location: login.php");
die("Redirecting to login.php");
}
if(!empty($_POST))
{
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
die("Invalid E-Mail Address");
}
if($_POST['email'] != $_SESSION['user']['email']['picture'])
{
$query = "
SELECT
1
FROM users
WHERE
email = :email
picture = :picture
";
$query_params = array(
':email' => $_POST['email']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$row = $stmt->fetch();
if($row)
{
die("This E-Mail address is already in use");
}
}
if(!empty($_POST['password']))
{
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
$password = hash('sha256', $_POST['password'] . $salt);
for($round = 0; $round < 65536; $round++)
{
$password = hash('sha256', $password . $salt);
}
}
else
{
$password = null;
$salt = null;
}
$query_params = array(
':email' => $_POST['email'],
':user_id' => $_SESSION['user']['id'],
':picture' => $_POST['picture'],
);
if($password !== null)
{
$query_params[':password'] = $password;
$query_params[':salt'] = $salt;
}
$query = "
UPDATE users
SET
email = :email
picture = :picture
";
if($password !== null)
{
$query .= "
, password = :password
, salt = :salt
";
}
$query .= "
WHERE
id = :user_id
";
try
{
// Execute the query
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$_SESSION['user']['email']['picture'] = $_POST['email'];
header("Location: private.php");
die("Redirecting to private.php");
}
?>
+1的實際使用準備好的語句和驗證輸入 –
您需要添加'電子郵件=之間的逗號:電子郵件圖片=:picture'。你正在檢查'$ _POST ['picture']'是否被設置? – andrewsi
還需要在SELECT的WHERE子句中使用AND,否? –