dongliang9682 2017-04-04 00:53
浏览 11
已采纳

PHP PDO错误语法

Can someone help me:

enter image description here

I got error when i write this

$check = $db->prepare("SELECT email FROM user WHERE email = ?");
if($check->rowCount() == 1){
    $error = "<div class ='text-danger'> Email Telah Digunakan </div>"; 
} else {
    $code = rand();
    $status = 0;
    try{
        $query = $db->prepare("INSERT INTO users(first_name,last_name,email,password,gender,code,status) VALUES (?,?,?,?,?,?,?,)");
        $query->execute([$first_name,$last_name,$email,password_hash($password,PASSWORD_DEFAULT),$gender,$code,$status]);   
    }
    catch(PDOException $e){
        echo"error:  " .$e->getMessage();
    }
}
  • 写回答

1条回答 默认 最新

  • drt5813 2017-04-04 01:00
    关注

    Ok, so you have a , at the end of your VALUES()'s list without something after it, which would lead to such syntax error. Here is the fixed version:

    $check = $db->prepare("SELECT email FROM user WHERE email = ?");
    if($check->rowCount() == 1){
        $error = "<div class ='text-danger'> Email Telah Digunakan </div>"; 
    }else{
        $code = rand();
        $status = 0;
        try{
            $query = $db->prepare("INSERT INTO users(first_name,last_name,email,password,gender,code,status) VALUES (?,?,?,?,?,?,?)");
            $query->execute([$first_name,$last_name,$email,password_hash($password,PASSWORD_DEFAULT),$gender,$code,$status]);
        }
        catch(PDOException $e){
            echo "error:  " .$e->getMessage();
        }
    }
    

    You where also missing a closing bracket for the if statement. Or maybe you copied wrongly. I've not actually checked full functionality, just the syntax errors I could find.

    A small tip

    If you format your code properly, you can find syntax errors a lot easier. A good code editor also helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效