Jump to content

Notice: Undefined variable: query_num_rows in C:\xampp\htdocs\register.php on line 19


Recommended Posts

I don't know what i'm doing wrong :

<?php
 
 
 if(isset($_POST['username'])&&isset($_POST['password'])) {
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  $password_hash = md5($password); 
 
 if (!empty($username)&&!empty($password)) {
  
 $query = "SELECT `id` FROM `users` WHERE `username`='$username' AND `password`='$password_hash'"; 
  if ($query_run = mysql_query($query)) {
 
   $query_num_rows = mysql_num_rows($query_run);
    if ($query_num_rows==0) {
     echo 'Invalid username or password';
   }
   }if ($query_num_rows==1)  {
      $user_id = mysql_result($query_run,0,'id');
$_SESSION['user_id']=$user_id;
header('location: require.php');
}
 }else {
header("Location:jquery.php") ;
}
 
 
 
 }
  
  
 
 
?>
 
<!doctype html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css.css"/>
</head>
<body>
<div class="lol">
<h1 class="header">Thecatch</h1>
 <div id="header"></div>
</div>
<form action="<?php  $current_file;?>" method="POST">
<div class="lol3">Email or Username<br/><input class="class1" type="text" name="username" size="19">
 
 
<label class="label" for="pass">Password</label> <input class="class2" type="password" name="password" size="19" >
<input class="classname" type="submit" Value="LogIn"><br>
<input class="check" type="checkbox" name="stay" value="Stay signed In"><p class="para7">Keep me logged in</p><br>
 
 
 </form></div>
</body>
</html>
 

Your code should be

<?php

if(isset($_POST['username']) && isset($_POST['password']))
{
    $username = mysql_real_escape_string($_POST['username']);
    $password = md5($_POST['password']); 

    if (!empty($username) && !empty($password))
    {
        $query = "SELECT `id` FROM `users` WHERE `username`='$username' AND `password`='$password'"; 
        if ($query_run = mysql_query($query))
        {
            if (mysql_num_rows($query_run) == 1)
            {
                $user_id = mysql_result($query_run,0,'id');
                $_SESSION['user_id'] = $user_id;
                header('location: require.php');
            }
            else
            {
                echo 'Invalid username or password';
            }
        }
        else
        {
            echo 'Query error: ' . mysql_error();
            exit;
        }
    }
    else
    {
        header("Location:jquery.php") ;
    }
}
 
?>
 
<!doctype html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css.css"/>
</head>
<body>
<div class="lol">
<h1 class="header">Thecatch</h1>
 <div id="header"></div>
</div>
<form action="<?php  $current_file;?>" method="POST">
<div class="lol3">Email or Username<br/><input class="class1" type="text" name="username" size="19">
 
 
<label class="label" for="pass">Password</label> <input class="class2" type="password" name="password" size="19" >
<input class="classname" type="submit" Value="LogIn"><br>
<input class="check" type="checkbox" name="stay" value="Stay signed In"><p class="para7">Keep me logged in</p><br>
 
 
 </form></div>
</body>
</html> 
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.