mssql_num_row需要1个参数资源

时间:2013-04-08 10:36:26

标签: php sql

这是我的代码:

    $link=mssql_connect($server, 'username','password');
if (!$link) {
    die('Something went wrong while connecting to the mssql database, it could be offline! ' . mssql_get_last_message());
}
mssql_select_db('GunzDB', $link);
$result="SELECT * FROM Account WHERE UserID = '$username'";

if(mssql_num_rows($result) > 0){
    echo "That username is already in use!";
} else{
    $result="SELECT * FROM Account WHERE Email = '$email'";

    if(mssql_num_rows($result) > 0){
        echo "That email is already in use!";
    } else{

        $query="INSERT INTO Account (UserID, UGradeID, PGradeID, RegDate, Name, Email) VALUES ('" . $username . "','0','0','00:00','" . $name . "','" . $email . "')";
        if($query){
            $result="SELECT * FROM Account WHERE UserID = '$username'";

            $row = mssql_fetch_array($result);
            $AID=$row['AID'];
            $query="INSERT INTO Login (AID, Password) VALUES ('" . $AID . "','" . $password . "')";
            if($query){
                echo "<span style='color: lime'>Your account has been successfully created!</span>";
            } else{
                echo "error with MSSQL: " . mssql_get_last_message();
            }
        } else{
            echo "error with MSSQL: " . mssql_get_last_message();
        }
    }
}

我一直收到这些错误

Warning: mssql_num_rows() expects parameter 1 to be resource, string given in /var/www/gunz/register.php on line 81

Warning: mssql_num_rows() expects parameter 1 to be resource, string given in /var/www/gunz/register.php on line 86

Warning: mssql_fetch_array() expects parameter 1 to be resource, string given in /var/www/gunz/register.php on line 94

它与这些行有关

$result="SELECT * FROM Account WHERE UserID = '$username'";

$result="SELECT * FROM Account WHERE Email = '$email'";

$result="SELECT * FROM Account WHERE UserID = '$username'";

3 个答案:

答案 0 :(得分:1)

您不执行任何查询:

$result= "SELECT * FROM Account WHERE UserID = '$username'";
if (mssql_num_rows($result) > 0){

它应该是:

$result = mssql_query("SELECT * FROM Account WHERE UserID = '$username'");
if (mssql_num_rows($result) > 0){

答案 1 :(得分:1)

您不应该将字符串作为mssql_num_rows

的输入

它应该是在执行mssql_query

后获得的资源

$query = mssql_query('SELECT * FROM a');

echo mssql_num_rows($query);

而不是

$query = 'SELECT * FROM a';

echo mssql_num_rows($query);

答案 2 :(得分:1)

你没有使用mssql_query()函数。

使用它:

$result=mssql_query("SELECT * FROM Account WHERE UserID = '$username'");

$result=mssql_query("SELECT * FROM Account WHERE Email = '$email'");

$result=mssql_query("SELECT * FROM Account WHERE UserID = '$username'");