druybew06513 2014-09-29 20:15
浏览 89
已采纳

php更新SQL语句不起作用

I'm trying to make a working login page, and I want to keep track of the successful and unsuccessful logins for the user.

I'm trying to do this with an update statement in php:

     $updateSQL="UPDATE login SET successfulLogins = IFNULL(successfulLogins, 0) + 1 
     WHERE username ='". $user ."'";
     $updateStmnt=$dbcon->prepare($updateSQL);
     $updateStmnt->execute();

Which gives me the error: Fatal error: Call to a member function execute() on a non-object

I tried manually entering the update statement in the database using SQL and it worked fine, so the issue is something to do with the php.. I think

Thanks

EDIT: I fixed this problem by closing dbcon earlier in the code, but now I have the same issue with this code:

    $isError=true;
    $errorMessage.="Username or password is incorrect<br />";

    $updateSQL="UPDATE login SET unsuccessfulLogins = IFNULL(unsuccessfulLogins, 0) + 1 
    WHERE username ='". $user ."'";
    $updateStmnt=$dbcon->prepare($updateSQL);
    $updateStmnt->execute();

I am now getting :

Warning: mysqli::prepare(): Couldn't fetch mysqli Fatal error: Call to a member function execute() on a non-object

  • 写回答

2条回答 默认 最新

  • duanjianxiu9400 2014-09-29 21:42
    关注

    Problem fixed. It was simply an issue of not closing $dbcon and $stmnt in the right places... I'm sure if I provided more code anybody could have told me that.

    Next time I'll post more of my code. I'm new to this website!

    Thanks!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料