dtkjthe4025 2015-08-29 05:24 采纳率: 0%
浏览 29

警告:mysql_num_rows()期望参数1是资源,布线在第18行的C:\ xampp \ htdocs \ LOGIN TEST \ login.php中给出[复制]

Hi im trying to do a very simple login system using php and mysql, it can be nonsecure

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\LOGIN TEST\login.php on line 18}

I followed the same exact guide from the internet and i still get this error ^

This is my following codes

<?php
$username = "root";
$password = "";
$hostname = "localhost";

$dbhandle = mysql_connect($hostname, $username, $password) or die("Could not connect to database");

$selected = mysql_select_db("login", $dbhandle);

$myusername = $_POST['user'];
$mypassword = $_POST['pass'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);

$query = "SELECT * FROM admin WHERE Username='$myusername' and Password='$mypassword'";
$result = mysql_query($query);
$count = mysql_num_rows($result);

  if($count==1) {
      echo 'It worked';
  }
  ?>

btw mysql is nonsecure

i also tried to input this code from this link

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xamppserver\htdocs\www\login.php on line 18

and i still got the same error....

this is my index.php

<body>
    <form action="login.php" method="POST">
        <p>Username:</p><input type="text" name="user" />
        <p>Password:</p><input type="password" name="pass" />
        <br />
        <input type="submit" value="Login" />
    </form>


</body>

this is the video which i followed

https://www.youtube.com/watch?v=NuiTzSdGmKM&feature=iv&src_vid=9SdqRKhZwfY&annotation_id=annotation_232683

</div>
  • 写回答

1条回答 默认 最新

  • dsfo22654 2015-08-29 05:43
    关注

    try this code....using mysqli

    <?php
    $mysqli = new mysqli("localhost","root","","login");
    if(mysqli_connect_errno())
    {
      trigger_error('Connection failed: '.$mysqli->error);
    }
    $myusername = $_POST['user'];
    $mypassword = $_POST['pass'];
    
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    
    $query = "SELECT * FROM admin WHERE Username='".$myusername."' and    Password='".$mypassword."' ";
    $result = $mysqli->query($query);
    
    if($result->num_rows>0)
       {
         echo 'It worked';
       }
    ?>  
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了