i have problem my login it's not running plzzz help me

<?php
session_start();
require("dbc.php");
if(isset($_POST['submit']))
{

 $username =mysql_real_escape_string( $_POST['username']); 
  $password =mysql_real_escape_string($_POST['password']);


if ($username && $password)
{
    $connect=mysql_connect("127.0.0.1","root","") or die("couldnt connect to database");
    mysql_select_db("login") or die("couldnt find database");
    $query = mysql_query("SELECT * FROM  `users` WHERE `username` ='$username'");

    $numrows = mysql_num_rows($qurey);


    if($numrows !=0) 
    {
    while($row = mysql_fetch_assoc($qurey))
    {
         $dbusername = $row['username'];
         $dbpassword = $row['password'];


         }
         if($username==$dbusername&&$pasword==$dbpassword)
         {
           echo "login succeful. <a href='membersarea.php'> click here to enter the member area</a>";
           $_SESSION['username'] = $dbusername ;
           }

           else

           echo "incorect password";
           }
           else 
            die ("that username dosent exist"); 
           }
         else  die (" please enter the username and password");


}


 ?>

Recommended Answers

All 26 Replies

i have problem my login it's not running plzzz help me

Describe your problem, what you have tried and any other relevant info. "It's not running" is just vague.

You have a type in your while loop.

 while($row = mysql_fetch_assoc($qurey))

Should be

 while($row = mysql_fetch_assoc($query))

thanxxxxxxxx alooooooooooooot my program is work now

Awesome, set the thread to solved if all is good now. Thanks :)

hi everyone now i face problem when i try register new username throw the web page it show that the username doesn't exist in my login.php and doesn't add in database here my code
register.php

<?php

error_reporting(0);

   if($_POST['submit'])

{

   $name=$_POST['name'];



   $username=$_POST['username'];

   $password=$_POST['password'];

   $password1=$_POST['password1'];

   $enc_Password=md5($password);



   if($name && $username &&$password &&$password1)

   {

   if(strlen($name)>30)



   {

   echo "your name is too long";

   }

   if(strlen($username)>10)

   {

      echo "your username is too long";

   }

   else

   {

   if(strlen($password)>15 || strlen($password)<6)

   {

      echo "your password must be btween 6 and 15 character";

   }

   if($password == $password1)

   {

       require "dbc.php";

       $query=mysql_query("INSERT INTO users VALUE('','$name','$usearname','$enc_password')");

       die("registeration complete! <a href='index.php'>click here to login</a>");

   }

   else

   {

   echo "password must match";

   }





   }



   }

   else

   echo "all fileds are required";

}













?>

<html>



<form action="register.php" method="POST">

  name:<input type="text" name="name" value="<?php echo "$name"; ?>"> Max Length:30<p>

  username:<input type="text" name="username" value="<?php echo "$username";?>"> Max Length:10<p>

  password:<input type="password" name="password"> Max Length:15<p>

  Re-Enter Password:<input type="password" name="password1"><p>



  <p>



  <input type="submit" name="submit" value="register">







  </form>



</html>

it show that the username doesn't exist in my login.php

What exactly does this mean? Does it give you an error message from PHP? Or an error message you've generated?

when i register tell regitration complete but when i insert it in my login they tell it dosen't exit and when i'm going to my database it dosen't insert it

Check the username that you are inserting. For instance, you declare username variable;

 $username=$_POST['username'];

and yet in your query, you are inserting;

'$usearname' and not $username

First correct that.

$query=mysql_query("INSERT INTO users VALUE('','$name','$usearname','$enc_password')");

VALUE should be VALUES too:

$query = mysql_query("INSERT INTO users VALUES ('', '$name', '$username', '$enc_password')");

still not been added in my database

i'm doing some changes in my register.php here the new code but still not been added in my database

<?php
error_reporting(0);
   if($_POST['submit'])
{
   $name=mysql_real_escape_string($_POST['name']);

   $username=mysql_real_escape_string($_POST['username']);
   $password=mysql_real_escape_string($_POST['password']);
   $password1=mysql_real_escape_string($_POST['password1']);
   $enc_Password=md5($password);

   if($name && $username &&$password &&$password1)
   {
   if(strlen($name)>30)

   {
   echo "your name is too long";
   }
   if(strlen($username)>10)
   {
      echo "your username is too long";
   }
   else
   {
   if(strlen($password)>15 || strlen($password)<6)
   {
      echo "your password must be btween 6 and 15 character";
   }
   if($password == $password1)
   {
       require "dbc.php";
       $query = mysql_query("INSERT INTO users VALUES ('', '$name', '$username', '$enc_password')");
       die("registeration complete! <a href='index.php'>click here to login</a>");
   }
   else
   {
   echo "password must match";
   }


   }

   }
   else
   echo "all fileds are required";
}






?>
<html>

<form action="register.php" method="POST">
  name:<input type="text" name="name" value="<?php echo "$name"; ?>"> Max Length:30<p>
  username:<input type="text" name="username" value="<?php echo "$username";?>"> Max Length:10<p>
  password:<input type="password" name="password"> Max Length:15<p>
  Re-Enter Password:<input type="password" name="password1"><p>

  <p>

  <input type="submit" name="submit" value="register">



  </form>

</html>

and here my code to connect to database
dbc.php

<?php
mysql_connect("127.0.0.1","root","") or die("couldnt connect to data base");
mysql_select_db("login") or die ("couldnt find data base");
?>

Shoud i insert any comment database to my register.php????

I suggest to try the following:

$query = mysql_query("INSERT INTO users VALUES ('', '$name', '$username', '$enc_Password')") or die(mysql_error());

Just noticed that you used a capital "P" on line 10. PHP is case-sensitive.

they show me this error(Column count doesn't match value count at row 1)

what i have suppose to do in my database?

It basically means, that the number of values that you are trying to insert do not match the number of columns in the table you are inserting to.

What are the columns names in the table you are inserting the data to?

my table is

id int auto increment
name varchar (25)
username varchar(25)
password varchar(25)

You might need to specify the column names in the query then.

$query = mysql_query("INSERT INTO users (id, name, username, password) VALUES ('', '$name', '$username', '$enc_Password')") or die(mysql_error());

If id is an auto increment either use this:

INSERT INTO users (NULL, '$name', '$username', '$enc_Password')

or this:

INSERT INTO users (name, username, password) VALUES ('$name', '$username', '$enc_Password')

now it insert it in my database but when i login the passwrd i pick up in register they tell incoorect password
i see in my tabels the password is the md5 password when i paste it in my login it works
how can solve this problem?thanx alot for helping

Your table column for password is varchar(25). An md5() result is 32 characters long, so it will be truncated and never match. Change the column length.

You also need to hash the password value from the login form to match it against the database value. I don't see that happening there.

$password = md5($password);

In addition to that, I am not sure if this typo was ever caught. $pasword?

if($username==$dbusername&&$pasword==$dbpassword)

is necessary to md5?in my register can delet it?i'm change the password varchar(15) still can't insert my password that i made they want the md5 to be login

i'm doing password varchar(32) but still want the md5 passowrd when i login

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.