1
我想在腳本中包含頁面以更改用戶個人資料的詳細信息。我就是這麼做的,在班上user.php的我這包括:編輯個人資料 - PDO
// Update profile
public function update($email,$gender,$location) {
try {
$stmt = $this->_db->prepare('UPDATE members SET email = ?, gender = ?, location = ? WHERE memberID = ? ');
$stmt->execute(array($email,$gender,$location,$_SESSION['memberID']));
return $stmt->fetch();
} catch(PDOException $e) {
echo '<p class="bg-danger">'.$e->getMessage().'</p>';
}
}
雖然,例如,頁面account.php我就是這麼做的:
if (isset($_POST['submit'])) {
// new data
$email = $_POST['email'];
$gender = $_POST['gender'];
$location = $_POST['location'];
$id = $_SESSION['memberID'];
// query
if ($user->update($email,$gender,$location,$id)); {
redirect('account.php');
}
}
而且,
<form action="account.php" method="POST">
Email<br>
<input type="text" name="email" value="<?php echo $_SESSION['email'] ?>" /><br>
Gender<br>
<input type="text" name="gender" value="<?php echo $_SESSION['gender'] ?>" /><br>
Location<br>
<input type="text" name="location" value="<?php echo $_SESSION['location'] ?>" /><br>
<input type="submit" name="submit" value="Save" />
</form>
使用PDO中的連接瞭解它的方式,但是,我嘗試了很多選項,但總是效果不佳。
歡迎來到Stack Overflow!這個問題在信息上有點短暫。你的問題是什麼? –
你好,我尋求幫助。我寫的代碼工作不正常,它不更新數據。那它呢?你可以幫幫我嗎? – Marco
它的更新語句,' - > fetch()'根本沒有意義,使用' - > rowCount()> 0'而不是 – Ghost