开发者

Comparing Value on Submit Vs Database

开发者 https://www.devze.com 2023-03-25 22:38 出处:网络
The \"dbcred.php\" class <?php # pdo_testdb_connect.php - function for connecting to the \"test\" database

The "dbcred.php" class

<?php
   # pdo_testdb_connect.php - function for connecting to the "test" database

   function testdb_connect ()
   {
     $dbh = new PDO("mysql:host=localhost;dbname=dbname", "root", "");
     return ($dbh);
   }
?>

PHP

<?php
#connect mysql
require_once "dbcred.php";
$dbh = testdb_connect ();

session_start(); 
$username = $_POST['regduser']; 
$userpass = md5($_POST['regdpass']); 
$result = mysql_query("SELECT * FROM Student WHERE regduser= '$username' AND regdpass = '$regdpass'");

if (mysql_num_rows($result)!= 1) {   $error = "Login failed"; 
 #include "loginform.php"; 
} else { 
 $_SESSION['username'] = "$username"; 
 $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; 
 #include "membersection.php"; 
}
?>

HTML

  <form action="inc/check_regUsr.php" method="post" id="userLogon">
        <div class="field required">
        Username: <input type="text" name="regduser" tabindex="1" /><br />
        </div>
        &开发者_JAVA技巧lt;div class="field required">
        Password: <input type="text" name="regdpass" tabindex="2" /><br />
        </div>
        <input type="submit" name="submitUser" />
    </form>

When I try to submit valid credentials it says: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in on line 12

Why does it not like this and how can I fix it?

Thank you


$result = mysql_query("SELECT * FROM Student WHERE regduser= '$username' AND regdpass = '$regdpass'");

I don't know how your database class is working. So I will write a general mysql connect code.

mysql_connect($host,$username,$password);
mysql_select_db($db);

No you can execute the query.

0

精彩评论

暂无评论...
验证码 换一张
取 消