下面是我用于递增的代码,它没有显示错误,但“like”列没有递增。
<?php
$id=$_GET['id'];
echo $id;
$dsn = 'mysql:host=127.0.0.1;dbname=as1';
$user = 'root';
$password = '';
try{
// Connect and create the PDO object
$pdo = new PDO($dsn, $user, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
echo 'Database connection failed - ';
echo $e->getMessage();
exit;
}
$sql="UPDATE photo SET likes = likes + 1 WHERE imagename=:id";
$q=$pdo->prepare($sql);
$q->execute(array($id));
header("Location:upload.php");
}