2

下面是我用于递增的代码,它没有显示错误,但“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");
}
4

2 回答 2

0
$sql="UPDATE photo SET likes = likes + 1 WHERE imagename=:id";
$q=$pdo->prepare($sql);
$q->bindParam(':id', $id, PDO::PARAM_INT);
$q->execute();

++从编程语言中知道的内容不适用于正常的 SQL 语法。

于 2013-09-27T10:19:01.840 回答
0
$sql="UPDATE photo SET likes = likes + 1 WHERE imagename=':id'";
于 2013-09-27T10:20:35.517 回答