-1
include_once "connect_to_mysql.php";
$query = mysql_query("SELECT * FROM  data WHERE Email = '$email'");
$num = array();
//Caculate the number of rows that have macthing username
$numrows = mysql_num_rows($query);
$num[] = $numrows;

if ($num != 0){
    $data = array('success' => 'true', 'message' => 'Incorrect Email');
    echo json_encode($data);
}

if 语句没有被处理并且没有 JSON 数据被回显,而是脚本冻结。
我究竟做错了什么?

4

4 回答 4

1
$result = mysql_query("SELECT COUNT(*) AS num FROM data WHERE Email = '$email'");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$num = intval($row['num']);
if ($num != 0) {
    $data = array('success' => 'true', 'message' => 'Email found');
} else {
    $data = array('success' => 'false', 'message' => 'Incorrect Email');
}
echo json_encode($data);
于 2012-10-18T10:09:46.860 回答
1

我不明白你为什么要使用$num[].

include_once "connect_to_mysql.php";
$email = $_POST['email'];
$query = mysql_query("SELECT * FROM  data WHERE Email = '$email'");
 $numrows = mysql_num_rows($query);
    if ($numrows != 0){
        $data = array('success' => 'true', 'message' => 'Correct Email');
        echo json_encode($data);
    }else{
        $data = array('success' => 'false', 'message' => 'Incorrect Email');
        echo json_encode($data);
    }

尝试使用以下 Jquery:

$.post('your_file.php',{email: 'your_email'},function(data){
  alert(data.success + ' ' + data.message);
},'json');
于 2012-10-18T11:29:48.813 回答
0

您正在将标量值提取$numrows到数组$num[]中,因此出现错误。尝试$numrows直接在 if 语句中使用,如下所示:

if ($numrows != 0){
于 2012-10-18T10:29:40.280 回答
0
$query = mysql_query("SELECT * FROM  data WHERE Email = '$email'");
if(mysql_num_rows($query)){
$data = array('success' => 'true', 'message' => 'Email found');
}
else{
$data = array('success' => 'false', 'message' => 'Incorrect Email');
}
echo json_encode($data);
于 2012-10-18T11:46:54.070 回答