在php中警告mysql_fetch_assoc()

时间:2014-11-29 03:48:06

标签: php

以下是警告信息:

  

警告:mysql_fetch_assoc()期望参数1是资源,   在第11行的E:\ HTML Learn \ Hocus \ profile.php中给出的对象

第11行是:

$get = mysql_fetch_assoc($check);

完整代码:

<?php include ( "./inc/header.inc.php" ); ?>
    <?php
        if (isset($_GET['u'])) 
        {
            $username = mysqli_real_escape_string($conn, $_GET['u']);
            if (ctype_alnum($username)) 
            {
                //cek user
                $conn = mysqli_connect("localhost", "root", "") or die("error MYSQL");
                mysqli_select_db($conn, 'skey');
                $check = mysqli_query($conn, "SELECT username, first_name FROM users WHERE username='$username'");
            if (mysqli_num_rows($check)==1) 
            {
                $get = mysql_fetch_assoc($check);
                $username = $get['username'];
                $firstname = $get['first_name'];
            }
            else
            {
                echo "<h2>User tidak terdaftar</h2>";
                exit();
            }
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

您正在混合mysqli_*mysql_*个功能。停止这样做。