使用会话用户ID将数据插入到正确的行中

时间:2014-02-02 13:18:19

标签: php mysql sql session

有没有人知道如何使用会话中的用户ID将数据插入到mysql数据库和正确的行中它将插入到数据库中而不是正确的行中这是我尝试过的代码。

<?php
$con=mysqli_connect("localhost","","","");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
':user_id' => $_SESSION['user']['id'], 
mysqli_query($con,"INSERT INTO login (code, link)
VALUES ('You Found a Secret Game!', '/12283719823838hdhj/') WHERE id = :user_id ");

mysqli_close($con);
?>

我尝试使用':user_id' => $_SESSION['user']['id'],,但它没有用。

1 个答案:

答案 0 :(得分:0)

我认为你需要这样做

<?php
$con=mysqli_connect("localhost","","","");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 mysqli_query($con,"INSERT INTO login (code, link)
VALUES ('You Found a Secret Game!', '/12283719823838hdhj/') WHERE id = " . 
$_SESSION['user']['id']);
mysqli_close($con);
?>

如果你看一下你正在推动的SQL,我想你会发现它试图检查id =:user_id而不是值:user_id