newbee i get the following error in the below mentioned code:
Parse error: parse error in C:\wamp\www\webdesigning1\webdesigning1\loginsession\login.php on line 25

<?php
	    $username = $_post ['username'];
            $password = $_post ['password'];
           if ($username&&$password)
           {
             $connect = mysql_connect {"localhost","root","webdesigning1") or die ("couldnt connect to mysql data base ");
             mysql_select_db("phplogin") or die("couldnt find db") ;
		  }
			 else
			 echo("enter username and password");
			 $query = mysql_query "SELECT * FROM `users` WHERE username =\'$username\'";
             $numrows = mysql_num_rows($query);
             if ($numrows!=0)
			 {
			 while ($row = mysql_fetch_assoc($query))
			 {
				 $dbusername=$row['username'];
				  $dbpassword=$row['password'];
			 }

			 if
			  ($username==$username&&$password==$password)
			  {
				echo  "You r in";
			  }
			  exit
         ?>

Recommended Answers

All 12 Replies

1. You should have started a new thread, instead of hijacking an old thread.
2. Use [ code ] tags to make your code readable.
3. Indicate which line is line 25.
4. The line starting with $connect = mysql_connect {" is wrong. Change { to (

commented: Thank! Please use "Flag Bad Post" feature for quick moderation. :) +11

Try to learn from this code snippet.

<?php
$username = $_post ['username'];
$password = $_post ['password'];

if (isset($username,$password))
    {
   $connect = mysql_connect ("localhost","root","webdesigning1") or die ("couldnt connect to mysql data base ");
    mysql_select_db("phplogin") or die("couldnt find db") ;
    $query = mysql_query("SELECT * FROM `users` WHERE `username`='$username' and `password`='$password'");
   if($row = mysql_fetch_assoc($query))
       {
	  $dbusername=$row['username'];
          $dbpassword=$row['password'];
	  if($dbusername==$username && $dbpassword==$password)
	       {
	 	echo  "You r in";
	        exit;
                }
      }
    else
      {
	 echo("enter username and password");
       }
 }
else
  {
       echo("enter username and password");
   }
?>

what do you mean by your reply i am unable to understand what u want to say

thanks

i copy pasted the above code which u sent but ut shows the following error:

Parse error: parse error in C:\wamp\www\webdesigning1\webdesigning1\loginsession\login.php on line 7

The php parser almost always points you right to the problem. In this case it has directed you to line 7.

I took a quick glimpse and immediately realized the left parenthesis was typo'd with a left curly brace: $connect = mysql_connect {"localhost","root","webdesigning1") or die ("couldnt connect to mysql data base "); This error exists in the original code you posted. If you don't make an effort to understand the problem or in this case, don't even look at the error message you're going to quickly find no one here wants to make an effort either.

Rule of thumb, when you get parse errors, look for mismatched/missing parenthesis, mismatched/missing quotes and missing semi-colons at the end of your lines. These are the most common I see on these forums.

commented: :) { +11

The php parser almost always points you right to the problem. In this case it has directed you to line 7.

I took a quick glimpse and immediately realized the left parenthesis was typo'd with a left curly brace: $connect = mysql_connect {"localhost","root","webdesigning1") or die ("couldnt connect to mysql data base "); This error exists in the original code you posted. If you don't make an effort to understand the problem or in this case, don't even look at the error message you're going to quickly find no one here wants to make an effort either.

Rule of thumb, when you get parse errors, look for mismatched/missing parenthesis, mismatched/missing quotes and missing semi-colons at the end of your lines. These are the most common I see on these forums.

sir ,
i can understand what you want to convey i have already worked on your instructions and now it gives me the followiing error.

Notice: Undefined variable: _post in C:\wamp\www\webdesigning1\webdesigning1\loginsession\login.php on line 2

Notice: Undefined variable: _post in C:\wamp\www\webdesigning1\webdesigning1\loginsession\login.php on line 3
enter username and password

<?php
$username = $_post ['username'];
$password = $_post ['password'];

if (isset($username,$password))
    {
   $connect = mysql_connect ("localhost","root","webdesigning1") or die ("couldnt connect to mysql data base ");
    mysql_select_db("phplogin") or die("couldnt find db") ;
    $query = mysql_query("SELECT * FROM `users` WHERE `username`='$username' and `password`='$password'");
   if($row = mysql_fetch_assoc($query))
       {
	  $dbusername=$row['username'];
          $dbpassword=$row['password'];
	  if($dbusername==$username && $dbpassword==$password)
	       {
	 	echo  "You r in";
	        exit;
                }
      }
    else
      {
	 echo("enter username and password");
       }
 }
else
  {
       echo("enter username and password");
   }
?>

your suggestions have worked for me thanks and in your current reply i have learnt one thing which i would never have learnt otherwise ,your last few lines"rule of the thumb"
thanks

I'm glad my suggestions made sense.

Your current errors are because your are referencing the $_POST superglobal array using lowercase. PHP is case sensitive $_post and $_POST are two different things.

The problem I see, is this is very very basic php. Without an understanding of the basics, you will not know where to look. I think developing a better understanding of that will greatly help you.

For myself, if I were to get an error like that, knowing the basics, I would realize that $_POST, $_GET etc are special variables within php. If I did not know that one of the first things I would do is google for "post, php" and look through and results from php.net first and foremost.

This page comes up as my second result: http://php.net/manual/en/reserved.variables.post.php upon looking at this page you will see that $_POST is ALWAYS referenced in capital letters. If you knew that post was a superglobal in php you might find the manual page for superglobals in php: http://php.net/manual/en/language.variables.superglobals.php

You would also notice that there is NEVER a space between a variable and its array key, again basic php. If you don't know about php arrays refer again to the manual: http://php.net/manual/en/language.types.array.php

Using the information I have provided, what do you think the necessary corrections should be?

commented: I HAD BEEN A NEW COMMER TO PHP .CAME ACROSS THIS WEBSITE AND FIRST OF ALL THIS PERSON HELPED PROMPTLY AND ACCURATELY .HE IS REALLY A MASTER.I APPRITITATE HIS PROMPT AND ACCURATE HELP +0

The previous error got solved successfully.Now that code is up and running .i need one thing to be soloved the if statment in last few lines .i have two databases in my phpmyadmin namely 'phplogin' and 'webdesigning1'
when i use 'phplogin' database enter password and id from that it shows " enter correct username and password' when i enter id password from second one it shows 'dosent exist' please see last lines of code in order to understand it better
thanks

<?php
$username = $_POST['username'];
$password = $_POST['password'];
if (isset($username,$password))
    {
   $connect = mysql_connect ("localhost","root","");
    mysql_select_db("phplogin");
   $query = mysql_query("SELECT * FROM `webdesigning1.table` WHERE username ='$username' and password='$password'");
   $numrows=mysql_num_rows($query);
   if ($numrows!=0)
   {
	   while($rows=mysql_fetch_assoc($query))
       (
	  $dbusername = $rows['username'];
      $dbpassword = $rows['password'];
	   )
	   if ($username=='dbusername'&&$password=='dbpassword')
	       {
echo "You r in";
	       }
elseif ($username!='$dbusername'&&$password!='$dbpassword')
		   
echo "Enter correct username and password!";
   }
   else
   die ("dosent exist");
	}
?>

The php parser almost always points you right to the problem. In this case it has directed you to line 7.

I took a quick glimpse and immediately realized the left parenthesis was typo'd with a left curly brace: $connect = mysql_connect {"localhost","root","webdesigning1") or die ("couldnt connect to mysql data base "); This error exists in the original code you posted. If you don't make an effort to understand the problem or in this case, don't even look at the error message you're going to quickly find no one here wants to make an effort either.

Rule of thumb, when you get parse errors, look for mismatched/missing parenthesis, mismatched/missing quotes and missing semi-colons at the end of your lines. These are the most common I see on these forums.

`webdesigning1.table` is not correct I think. Try removing the ` or try `webdesigning1`.`table`

`webdesigning1.table` is not correct I think. Try removing the ` or try `webdesigning1`.`table`

presently i have nothing to do with `webdesigning1.table` i am using phplogin database instead
the problem is when i enter a correct user id and password it shows Enter correct username and password! while as it is supposed to show you are in as per the code shown.i think the problem lies in this section

$numrows=mysql_num_rows($query);
   if ($numrows!=0)
   {
	   while($rows=mysql_fetch_assoc($query))
       {
	  $dbusername = $rows ['username'];
      $dbpassword = $rows ['password'];
	   }
	   if ($username=='dbusername'&&$password=='dbpassword')
	       {
			   echo "You r in";
	       }
elseif ($username!='$dbusername'&&$password!='$dbpassword')
		   
echo "Enter correct username and password!";
   }
   else
   die ("dosent exist");
	}

webdesigning1.table means it looks for the table named table in the database named webdesigning1. If you don't use that, remove it. It is looking in the wrong database. Unless you already changed the code of course.

You may want to look at the password checking and to be certain, add some parenthesis in the check. Crap, I see now. You assign your record to $dbXXXX variable, but use a different one in your if.

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

Look your query

$query = mysql_query "SELECT * FROM `users` WHERE username =\'$username\'";

as you say your login information stored in phplogin DB so use this simple query

$query = mysql_query "SELECT * FROM phplogin WHERE username ='$username'";

i think it will work;

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.