0

Hey,
I'm having a problem executing the following code:

<?php
session_start();
require('connect.php');
if($_POST['username'])){
  $name=$_POST['username'];
  $checkUsername = mysql_query("select * from users where UserName='$name'");
  if(mysql_num_rows($checkUsername){
    echo 'Logged in successfully!';
    $_SESSION['username'] = $name;
  }
  else{
    echo 'The username or password you've entered is not valid!';
  }
}
?>
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Paaat
0

Actually, the problem you're facing is not in MySQL. :)
I think you only have to close the IF Condition bracket in the line #7 so it becomes:

if(mysql_num_rows($checkUsername)){

Another mistake is in the line #12 where you have to escape the quotation mark in "you've" like this:

echo 'The username or password you\'ve entered is not valid!';

To be more careful and avoid other errors, however, add this before the semicolon in the line #6:

or die(mysql_error())

Edited by Pro2000: n/a

0
if(mysql_num_rows($checkUsername)){

should be

if(mysql_num_rows($checkUsername)>0){
1

:yawn: Oh! How could I forget to type it!

Votes + Comments
Heh, I think you'd better take a nap. :) Thank you anyway.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.