我需要制作一个PHP代码,从服务器获取数据,更新数据并向用户更新数据。我是PHP的初学者,所以我不知道如何做到这一点。这是我现在拥有的代码。从数据库中选择数据并进行更新PHP/PDO
那么如何更改代码以使其更新数据?
<?php
include 'config.php';
$ID = $_GET['ID'] ;
$sql = "select * from table where ID = \"$ID\" and condition = false ";
// This is what I need the table to be updated "Update table where where ID = \"$ID\" set condition = true" ;
try {
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->query($sql);
$data = $stmt->fetchAll(PDO::FETCH_OBJ);
$dbh = null;
echo '{"key":'. json_encode($data) .'}';
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
?>
是否要选择或更新?你的sql查询是用于select的。 – 2012-04-17 10:29:04
我想选择数据然后更新它。更新查询是在评论中,但我不知道在哪里以及如何把它。 – user1323294 2012-04-17 10:33:03
你想更新什么?你为什么要用相同的值更新你的数据库? – Bono 2012-04-17 10:39:27