简体   繁体   English

查询未插入,但也不给出错误

[英]Query not inserting, but not giving error either

I got this query and it's not inserting into the database but it's not giving an error either. 我得到了这个查询,它没有插入数据库,但也没有给出错误。

        try {
        $sth = $Db->dbh->prepare("INSERT INTO users (username,password,email,phone,first_name) VALUES (:username,:password,:email,:phone,:firstname)");
        $sth->execute(array(':username' => $username,':password' => $password, ':email' => $email,':phone' => $phone,':firstname'=>$firstname));
    } catch(Exception $e) {
        echo $e->getMessage();
        exit();
    }

在此处输入图片说明 I've tried inserting the query by command and it works fine. 我试过通过命令插入查询,它工作正常。 There are other insert queries on the site and those work fine too.. I'm not sure what I'm doing wrong here 该网站上还有其他插入查询,这些查询也可以正常工作。.我不确定我在做什么错

Can you try something like this? 你可以尝试这样的事情吗?

try
{
    // Prepare Statement
    if (!($stmt = $mysqli->prepare("INSERT INTO users (username,password,email,phone,first_name) VALUES (?,?,?,?,?)")))
        throw new Exception("Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error);

    // Bind Parms
    if (!$stmt->bind_param("sssss", $username, $password, $email, $phone, $firstname))
        throw new Exception("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error);

    // Execute Statement
    if (!$stmt->execute())
        throw new Exception("Execute failed: (" . $stmt->errno . ") " . $stmt->error);
}
catch (Exception $ex) {
    exit('Error: '. $ex->getMessage());
}

PS As TiiJ7 suggestion on the comment to your question, are those two columns perm and rank - are they nullable columns? PS至于TiiJ7对你的问题的意见建议,是那些两列permrank -他们nullable列? if not, you might have to specify a value at the time of row insertion. 如果不是,则可能必须在插入行时指定一个值。

More info here: http://php.net/manual/en/mysqli.quickstart.prepared-statements.php 此处的更多信息: http : //php.net/manual/en/mysqli.quickstart.prepared-statements.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM