duanmingting9544 2014-05-14 12:45
浏览 39
已采纳

警告:mysql_num_rows()期望参数1是资源,第17行/var/customers/webs/ni272979_1/Loader/login.php中给出的布尔值[重复]

<?php
$filename = 'install.php';
if (file_exists($filename)) {
echo ("<center><font color='red'><b>/install.php still exists<br>
After installing please delete install.php</center></font></b>");
} else {
if (isset($_POST['Login'])){
include('config.php');
    if (!mysql_connect($host, $username, $password)) die("Can't connect to database");
    if (!mysql_select_db($db_name)) die("Can't select database");
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' or die(mysql_error());";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
    if($count >= 1){
    session_register("myusername");
    session_register("mypassword");
    header("location: index.php");
    } else {

    }
}

?>

I have tried to fix it but not sucsessfuly. I don't know how i can fix it because i am a php noob.

</div>
  • 写回答

1条回答 默认 最新

  • doujin8673 2014-05-14 12:47
    关注

    You have an error in your query. It should be something like this.

    $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword';";
    

    And then you can do something like this.

     $result=mysql_query($sql) or die(mysql_error());
    

    Also try using MySQLi or PDO function for CRUD operations.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题