doy51723 2014-05-28 20:49
浏览 114
已采纳

PHP无法打印mysql_query()结果

I have code

$email = "jb@tlb.com";    
$row = mysql_query("SELECT EXISTS(SELECT email FROM accounts WHERE email='".$email."');");
echo $row[0];

However, nothing is echoed.

This is strange because something is being returned because, later in the code I have a function that is CALLED:

if ( $row[0] == 0 ) { echo "Email address is available<br>";};

However: this is strange because when i put the SAME CODE into mySQL database command prompt:

enter image description here

It clearly returns 1 or TRUE.

The mysql_query is returning 0 when the same exact command in mysql command prompt returns 1. Further: I am unable to echo the result for debugging purposes.

EDIT: Please not, the regular mySQL command is returning this and ONLY this: enter image description here

EDIT: Here is there entire database: enter image description here

  • 写回答

3条回答 默认 最新

  • druzuz321103 2014-05-28 20:56
    关注

    MySQL query gives you a ressource. After that you have to fetch the data with mysql_fetch_assoc or mysql_fetch_row or something else for example. But its better to use prepared statements with mysqli or PDO to get more security.

    $email = "jb@tlb.com";    
    $res = mysql_query("SELECT EXISTS(SELECT email FROM accounts WHERE email='".myql_real_escape_string($email)."')");
    $row = mysql_fetch_assoc($res);
    echo $row['email'];
    

    Answer to your question:

    $email = "jb@tlb.com";    
    $res = mysql_query("SELECT email FROM accounts WHERE email='".mysql_real_escape_string($email)."')");
    $numRows = mysql_num_rows($res);
    
    if($rowRows > 0) {
        echo "Record Available";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳