我一直在环顾四周,甚至在网站上,但我无法在PDO中找到正确的语法来更新数据,例如用户配置文件的数据。在PDO中更新数据
你可以给我一个实际的例子与HTML格式? 我知道,也许我问了这么多,但我无法让它工作。
我附上了什么,直到现在已经能够做,但没有工作。
if(isset($_POST['submit'])) {
$email = $_POST['email'];
$location = $_POST['location'];
$id = $_SESSION['memberID'];
$stmt = $db->prepare("UPDATE `members` SET `email` = :email, `location` = :location WHERE `memberID` = :id");
$stmt->bindParam(":email", $email, PDO::PARAM_STR);
$stmt->bindParam(":location", $location, PDO::PARAM_STR);
$stmt->bindParam(":id", $_SESSION['memberID'], PDO::PARAM_STR);
$stmt->execute(array(':email' => $_POST['email'], ':location' => $_POST['location'], ':id' => $id));
}
而且,
<form role="form" method="POST" action="<?php $_PHP_SELF ?>">
<div class="form-group">
<label class="control-label">Email</label>
<input type="text" value="<?php echo $_SESSION['email'] ?>" name="email" id="email" class="form-control"/>
</div>
<div class="form-group">
<label class="control-label">Location</label>
<input type="text" value="<?php echo $_SESSION['location'] ?>" name="location" id="location" class="form-control"/>
</div>
<div class="margiv-top-10">
<input type="submit" name="submit" class="btn green" value="Update" >
<a href="profile.html" class="btn default">Annuller </a>
</div>
</form>
我想知道,如果它是安全的,正确的查询相同的页面,或者我应该创建一个类?你能帮助一个实际的例子,因为我已经尝试了一切。
什么不起作用? – Rasclatt
如果你有' - > bindParam',' - > execute()'应该有空参数,你不需要同时拥有这两个参数。或者删除所有' - > bindParam'语句,并使用' - > execute'以及数组参数 – Ghost
我只是想说... double bind是不行的。 – Rasclatt