为什么我收到错误:查询为空?

时间:2011-11-28 15:25:01

标签: php mysql sql

我正在为我的网页创建一个登录部分。当一个新人注册他们的详细信息时,按下注册按钮会转到register_ok部分,如下所示:

case 'register_ok':



if (!$_POST['client_username'] || !$_POST['client_password'] ||
     !$_POST['client_email']) {
    die('You did not fill in a required field.');
}

// check if username exists in database.

if (!get_magic_quotes_gpc()) {
    $_POST['client_username'] = addslashes($_POST['client_username']);
}

$qry = "SELECT client_username FROM client WHERE client_username = '".$_POST['client_username']."'";
$result = mysql_query($qry);
    if($result) {
        if(mysql_num_rows($result) > 0) {
    die('Sorry, the username: <strong>'.$_POST['client_username'].'</strong>'
      . ' is already taken, please pick another one.');
    }

}


// check e-mail format

if (!preg_match("/.*@.*..*/", $_POST['client_email']) ||
     preg_match("/(<|>)/", $_POST['client_email'])) {
    die('Invalid e-mail address.');
}

// no HTML tags in username, website, location, password

$_POST['client_username'] = strip_tags($_POST['client_username']);
$_POST['client_password'] = strip_tags($_POST['client_password']);



// now we can add them to the database.
// encrypt password

$_POST['client_password'] = md5($_POST['client_password']);

if (!get_magic_quotes_gpc()) {
    $_POST['client_password'] = addslashes($_POST['client_password']);
    $_POST['client_email'] = addslashes($_POST['client_email']);

}



$insert = "INSERT INTO client (
        client_username, 
        client_password, 
        client_name, 
        client_email, 
        client_last_access)

        VALUES (
        '".$_POST['client_username']."', 
        '".$_POST['client_password']."',  
        '".$_POST['client_name']."', 
        '".$_POST['client_email']."',
        'now()'
        )";

        if(!mysql_query($sql,$con)) {
            die('Error: ' . mysql_error());
        }

        else{

$id= mysql_insert_id();

session_start();


            echo '<script>alert("You May Now Login");</script>';
            echo '<meta http-equiv="Refresh" content="0;URL=pv.php">';
        }


break;
}

当我注册一个新人时,我收到以下错误:

错误:查询为空

为什么会这样?

2 个答案:

答案 0 :(得分:0)

执行:

if(!mysql_query($sql,$con)) { 

if(!mysql_query($insert,$con)) {

您的变量名称不正确

答案 1 :(得分:0)

if(!mysql_query($sql,$con)) {行中,您的意思是$insert而不是$sql吗?