Jump to content

error in my code , login script


Glenskie

Recommended Posts

i just recently bought hosting with hostmonster and im putting my login script on the site and it is not working here is the error im getting

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/quickdai/public_html/login.php on line 36

 

 

<?php // Start Session to enable creating the session variables below when they log in
session_start();
// Force script errors and warnings to show on page in case php.ini file is set to not display them
error_reporting(E_ALL);
ini_set('display_errors', '1');
//-----------------------------------------------------------------------------------------------------------------------------------
// Initialize some vars
$errorMsg = '';
$email = '';
$pass = '';
$remember = '';
if (isset($_POST['email'])) {

$email = $_POST['email'];
$pass = $_POST['pass'];
if (isset($_POST['remember'])) {
$remember = $_POST['remember'];
}
$email = stripslashes($email);
$pass = stripslashes($pass);
$email = strip_tags($email);
$pass = strip_tags($pass);

// error handling conditional checks go here
if ((!$email) || (!$pass)) { 

$errorMsg = '<font color="red">Please fill in both fields</font>';

} else { // Error handling is complete so process the info if no errors
include 'connect_to_mysql.php'; // Connect to the database
$email = mysql_real_escape_string($email); // After we connect, we secure the string before adding to query
   //$pass = mysql_real_escape_string($pass); // After we connect, we secure the string before adding to query
$pass = md5($pass); // Add MD5 Hash to the password variable they supplied after filtering it
// Make the SQL query
       $sql = mysql_query("SELECT * FROM Admin WHERE email='$email' AND password='$pass'"); 
$login_check = mysql_num_rows($sql);
       // If login check number is greater than 0 (meaning they do exist and are activated)
if($login_check > 0){ 
      while($row = mysql_fetch_array($sql)){


// Create session var for their raw id
$id = $row["id"];   
$_SESSION['id'] = $id;
// Create the idx session var
$_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id");



      } // close while

      // Remember Me Section


      // All good they are logged in, send them to homepage then exit script
      header("location: 25xc54df.php"); 
      exit();

} else { // Run this code if login_check is equal to 0 meaning they do not exist
   $errorMsg = "Please leave now before your ip is banned ";
} 


   } // Close else after error checks

} //Close if (isset ($_POST['uname'])){
?>
<html>
<div id="form">
 <form id="signinform" action="login.php" method="post" enctype="multipart/form-data" name="signinform">
   <fieldset>


    <div id="legend">Log in</div>
    <br>
     <label for="login">Email</label>
     <input type="text" id="email" name="email" />
     <div class="clear"></div>

     <label for="password">Password</label>
     <input type="password" id="password" name="pass" />
     <div class="clear"></div>

     <div class="clear"></div>

     <br />

     <input type="submit" style="margin: -20px 0 0 287px;" class="button" name="commit" value="Sign In"/> 
   </fieldset><?php print "$errorMsg"; ?>
 </form>
 </div>
 </div>

Link to comment
Share on other sites

Your query is failing, so mysql_query() returns FALSE. You are then passing this value to mysql_num_rows(), which expects a resource to be passed. As requinix said, checking the return value of mysql_error() will tell you what went wrong with your query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.