dongzhiyi2006 2014-04-09 20:54
浏览 47

检查用户名和电子邮件是否存在于数据库中或不在mysql中

    $valid = mysqli_query($com,"select username,email from company_profile where username = ".$uname." or email = ".$email." ");
if ($valid=="")
{echo "email n username exists";}
else
{
echo "reg success";
}

Here is my code, it doesn't work is i was also sure. want to return result weather email or username exists in db or not. what's the way to do it.

  • 写回答

1条回答 默认 最新

  • dp7311 2014-04-09 21:05
    关注

    The mysqli_query method returns a resultset, not a scalar.

    $result = mysqli_query($com, "SELECT ...", MYSQLI_STORE_RESULT);
    
    if ( $result->num_rows() > 0 ) {
       echo "query returned at least one row";
    }
    

    The code looks vulnerable to SQL injection, we don't see any references to the mysqli_real_escape_string function.

    We'd prefer to see a prepared statement with bind variables, e.g.

    if ($stmt = mysqli_prepare($com, "SELECT username,email from company_profile"
                  . " where username = ? OR email = ? "))
    {
       mysqli_stmt_bind_param($stmt, "ss", $uname, $email);
       mysqli_stmt_execute($stmt);
       $result = mysqli_stmt_get_result($stmt);
       while ($row = mysqli_fetch_array($result))
       {
    
       }
       mysqli_stmt_close($stmt);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看