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!';
  }
}
?>

Recommended Answers

All 4 Replies

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())
if(mysql_num_rows($checkUsername)){

should be

if(mysql_num_rows($checkUsername)>0){

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

commented: Heh, I think you'd better take a nap. :) Thank you anyway. +3

Thank you. It's solved now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.