mysqli_query()不会工作

时间:2014-06-15 08:42:02

标签: php mysql sql mysqli

我似乎无法获取我的代码来执行查询。数据库连接正常,但每当我尝试运行mysqli_query()时,都没有任何反应。我一直在四处寻找,但似乎无法找到问题。

  

require_once("globals.php");

declareLocals();

$mysqli = mysqli_connect($GLOBALS["mysql_host"], $GLOBALS["mysql_user"], $GLOBALS["mysql_pass"], $GLOBALS["mysql_db"]);

if(mysqli_connect_errno()) {
    ?> <script type="text/javascript">alert("Can't connect to MySQL database!");</script>
    <?
    echo mysqli_connect_error();
}

$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);

login($mysqli, $username, $password);

function login($con, $username, $password) {
    echo "Username: " . $username . "</b>";
    echo "Password: " . $password . "</b>";
    echo "Checking username in database.";


    //$qry = "SELECT 'userid' FROM 'users')";

    $sql = "INSERT INTO `users`(`userid`, `username`, `password`, `isadmin`) VALUES (\'1\',\'testuser\',\'testpw\',\'0\')";

    $result = mysqli_query($cons, $sql);
    echo $result;   
    echo mysqli_error();
} ?>`

此代码不会引发错误,不会在连接时也不会引发错误。查询($ sql或$ qry)都不会执行,当我检查$ result是否等于null时,它返回true。我使用的查询直接来自PhpMyAdmin,我知道结果不是null。

0 个答案:

没有答案