0

see this code

<?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 `users` WHERE username ='$username' and password='$password'");
   $numrows=mysql_num_rows($query);
   if ($numrows!=0)
   {
	   while($row = mysql_fetch_assoc($query))
       {
	  $dbusername = $row ['username'];
      $dbpassword = $row ['password'];
	   }
	  if ($dbusername=='username'&&$dbpassword=='password')
	     {
		  echo ("You r in");
		 }
	     else
		
        echo ("incorrect password");
          }
		else
		die ("that user dosen't exist");
   }
   else
   die("please enter username and password");
   ?>

the problem is when we enter correct id and password it jumps to echo ("incorrect password"); where as it shall echo "you are in " if anybody can help that will be most kindness
thanks

5
Contributors
21
Replies
27
Views
6 Years
Discussion Span
Last Post by Zagga
Featured Replies
  • 1

    Hi again imti321, I'm sorry if I sounded impatient, that wasn't my intention. Your script is taking 2 vartiables ($section and $page) and is combining them into a third variable ($path) and then it's trying to include that file. So, if $section was set to "inc" and if $page was … Read More

0

try this:

<?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 `users` WHERE username ='$username' and password='$password'");
   $numrows=mysql_num_rows($query);
   if ($numrows==0)
   {
  	 die("Incorrect username / password");
   }
}
else
{
	die("please enter username and password");
}

   ?>
0

i tried this one but same problem can you correct me without deleting my code.hurrah i am editing this code because i soloved it with my own code without deleting it i changed the line

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

to

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

and it works but i am unable to understand why it is displaying it so however first code was right in my view

Edited by imti321: found the answer myuself

0

i think you wrote unnecessary code.. check it once..

May be but it is correct .please tell where the mistake lies.everything is working fine except when it is supposed to jump to

echo "You r in!<a href='member.php'Click </a> here to enter the member area";

it jumps to

echo "Incorrect password!";

and when i change the line

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

to

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

it jumps to the required line

<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
    {
   $connect = mysql_connect ("localhost","root","") or die("Couldn't connect");
   mysql_select_db("phplogin")or die("Couldn't find db");
   $query = mysql_query("SELECT * FROM `users` WHERE username ='$username' and password='$password'");
	
   $numrows = mysql_num_rows($query);
   
if ($numrows!=0)
   {
	   while($row = mysql_fetch_assoc($query))
    {
	  $dbusername =$row['username'];
      $dbpassword =$row['password'];
	}
	if     ($username=='$dbusername'&&$password=='$dbpassword')
	{
	              echo "You r in!<a href='member.php'Click </a> here to enter the member area";
				  $_SESSION['username']==$username;
	}
	else
	   echo "Incorrect password!";
   }
   else
     die ("That user dosent exist");
  	}
	else
	   die("Please enter username and password");
	   ?>
0

May be but it is correct .please tell where the mistake lies.everything is working fine except when it is supposed to jump to

echo "You r in!<a href='member.php'Click </a> here to enter the member area";

it jumps to

echo "Incorrect password!";

and when i change the line

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

to

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

it jumps to the required line

<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
    {
   $connect = mysql_connect ("localhost","root","") or die("Couldn't connect");
   mysql_select_db("phplogin")or die("Couldn't find db");
   $query = mysql_query("SELECT * FROM `users` WHERE username ='$username' and password='$password'");
	
   $numrows = mysql_num_rows($query);
   
if ($numrows!=0)
   {
	   while($row = mysql_fetch_assoc($query))
    {
	  $dbusername =$row['username'];
      $dbpassword =$row['password'];
	}
	if     ($username=='$dbusername'&&$password=='$dbpassword')
	{
	              echo "You r in!<a href='member.php'Click </a> here to enter the member area";
				  $_SESSION['username']==$username;
	}
	else
	   echo "Incorrect password!";
   }
   else
     die ("That user dosent exist");
  	}
	else
	   die("Please enter username and password");
	   ?>

Thanks Guys
soloved it again myself the problem was in this line

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

and it took me 4 days to remove inverted commas from it the correct one is

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

t

0

tutorials working login dosent "home showing following errors
Notice: Undefined index: page in C:\wamp\www\webdesigning1\index.php on line 28

Notice: Undefined variable: path in C:\wamp\www\webdesigning1\index.php on line 33
Page doesnt exist

<html>

<table width='70%' align='center'>
<tr>
<td>
<img src="/webdesigning1/inc/b.png">
</td>
</tr>
</table>
<table width='31%' height="103" align='center'>
<tr>
<td>
<a href='index.php'>Home</a><br>
<a href="index.php?page=tutorials">Tutorials</a>

</td>
<td width='80%'> <body bgcolor='#9999CC'><table width="70" align="left">

     <form action='login.php' method='post'>
           username: <input type='text' name='username'><br>
            password:<input type='password' name='password'><br>
            <input type='submit' value='Login'>
  </form>
</body>

<?php
{
$page = $_GET ['page'];

if ($page)

$path="inc/".$page.".php";
if (file_exists($path))
{
include($path);
}

else

echo "Page doesnt exist.";
}
?>
</td>
</tr>
</table>
</html>
0

Hi imti321,

Line 28 is trying to find a $_GET variable. Are you certain this has been set?

Also, you have a syntax error. The { symbol on line 27 should come after the first IF statement. The start of the PHP should read . . .

<?php
$page = $_GET['page'];
if ($page)
[B]{[/B]
$path="inc/".$page.".php";

Hope this helps.
Zagga

0

Please tell me what i have to do in order to set $GET THE PROBLEM LIES HERE

<?php

$page = $GET ['page'];

if ($page)
{
$path="inc/".$page.".php";
if (file_exists($path))
{
include($path);
}

else

I HAVE MY INDEX FILE IN C:\wamp\www\webdesigning1 AND ALL OTHER E.G LOGIN ,LOGOUT ETC IN C:\wamp\www\webdesigning1\inc FOLDER

Hi imti321,

Line 28 is trying to find a $_GET variable. Are you certain this has been set?

Also, you have a syntax error. The { symbol on line 27 should come after the first IF statement. The start of the PHP should read . . .

<?php
$page = $_GET['page'];
if ($page)
[B]{[/B]
$path="inc/".$page.".php";

Hope this helps.
Zagga

0

$_GET[page] will try to find a variable called page in the URL (that is how $_GET works).

Where is this variable being defined? I assume that somewhere the user selects the page they want to include but you don't show this code.

Try placing this line straight after you open PHP

echo "The variable is " . $_GET['page'];

If it doesn't show the page, then $_GET isn't being set, or isn't being carried to this page.

0

when i try to login from localhost and click "webdesigning1" i get this error on clicking "home"
Notice: Undefined index: page in C:\wamp\www\webdesigning1\index.php on line 28
while as it recognises "tutorials" login dosent work
and when i change $_GET to $GET it gives this message
Notice: Undefined variable: GET in C:\wamp\www\webdesigning1\index.php on line 28
and login still dosent work

$_GET[page] will try to find a variable called page in the URL (that is how $_GET works).

Where is this variable being defined? I assume that somewhere the user selects the page they want to include but you don't show this code.

Try placing this line straight after you open PHP

echo "The variable is " . $_GET['page'];

If it doesn't show the page, then $_GET isn't being set, or isn't being carried to this page.

0

Listen sir i am new to php therefore need a patient hearing.
i wrote ,as per your saying, the line

echo "The variable is " . $_GET['page'];

after opening remarks of php it gives the following error

Notice: Undefined index: page in C:\wamp\www\webdesigning1\index.php on line 32
The variable is 
Notice: Undefined index: section in C:\wamp\www\webdesigning1\index.php on line 33

Notice: Undefined index: page in C:\wamp\www\webdesigning1\index.php on line 34

although i am almost completing this session but you r telling me to set $_GET but i dont know how to can you eloberate a little more
thanks for continious support

I ask again, where are you defining $_GET?

my index has now changed a little additions

<html>

<table width='70%' align='center'>
<tr>
<td>
<img src="/webdesigning1/inc/b.png">
</td>
</tr>
</table>
<table width='31%' height="103" align='center'>
<tr>
<td>
<a href='index.php'>Home</a><br>
<a href="index.php?page=tutorials">Tutorials</a>
<a href="index.php?page=login">Login</a>
<a href="index.php?page=logout">Logout</a>
<a href="index.php?page=member">Member area</a>
<a href="index.php?page=videos1">vedio area</a>

</td>
<td width='80%'> <body bgcolor='#9999CC'>

     <form action='login.php' method='POST'>
           username: <input type='text' name='username'><br>
            password:<input type='password' name='password'><br>
            <input type='submit' value='Login'>
  </form>
</body>
<td width="70%"

<?php
echo "The variable is " . $_GET['page'];
$section = $_GET ['section'];
$page = $_GET['page'];

if ($page)
{
	
	//check for sections
	if (!$section)
$section="inc";
$path= $section."/".$page.".php";

if (file_exists($path))
{
include($path);
}
else
{
echo "Sorry that Page doesnt exist.";
}
}
?>
</td>
</tr>
</table>
</html>

Edited by imti321: addition of code

1

Hi again imti321,
I'm sorry if I sounded impatient, that wasn't my intention.

Your script is taking 2 vartiables ($section and $page) and is combining them into a third variable ($path) and then it's trying to include that file.

So, if $section was set to "inc" and if $page was set to "mypage", your code would include "inc/mypage.php".

To make this code work, you need to set 2 variables ($section and $page).
At the moment, you are trying to make $section the same as $_GET but you haven't told the script what $_GET is.

Try replacing all the php code (lines 31 to 53) with the following code.

<?php
$section = "inc";
$page = "mypage";  // enter the name of the page you want included here.

$path = $section . "/" . $page . ".php";
if (file_exists($path))
  {
  include ($path);
  }
else
  {
  echo "Sorry, that page doesnt exist.";
  }
?>

Is this what you were trying to do, or did you want the user to be able to choose what file is included?


Zagga

Votes + Comments
Good Explanation..Keep it up.
0

i placed the code as you told although it does not give any error but it does not display the target page i think the problem lies in this line

$page ="page";

do i have to enter the name of a page which is in
"inc" folder or just write "page" then i shall have to enter like this every page over ther if so please tell how thanks

Hi again imti321,
I'm sorry if I sounded impatient, that wasn't my intention.

Your script is taking 2 vartiables ($section and $page) and is combining them into a third variable ($path) and then it's trying to include that file.

So, if $section was set to "inc" and if $page was set to "mypage", your code would include "inc/mypage.php".

To make this code work, you need to set 2 variables ($section and $page).
At the moment, you are trying to make $section the same as $_GET but you haven't told the script what $_GET is.

Try replacing all the php code (lines 31 to 53) with the following code.

<?php
$section = "inc";
$page = "mypage";  // enter the name of the page you want included here.

$path = $section . "/" . $page . ".php";
if (file_exists($path))
  {
  include ($path);
  }
else
  {
  echo "Sorry, that page doesnt exist.";
  }
?>

Is this what you were trying to do, or did you want the user to be able to choose what file is included?


Zagga

-1

try this

$page = isset($GET ['page']) : $GET ['page'] : '';

if($page)
{
$path="inc/".$page.".php";

if(isset($path))
{
 if (file_exists($path))
 {
  include($path);
 }
 else
 {
  echo "Page doesnt exist.";
 }
}
0

Hi imti321,

do i have to enter the name of a page which is in "inc" folder

Yes, you have to enter the name of the page.

0

Hi imti321,

Yes, you have to enter the name of the page.

but i did it without entering the page name ,actually i made pages including index from ConTEXT and opened them in dreamweiver that was creating problems i copied the same content and creating new pages in dreamveiwer that worked and changed my index file like this

<html>

<table width='70%' align='center'>
<html>

<table width='70%' align='center'>
<tr>
<td>
<img src="/webdesigning1/inc/b.png">
</td>
</tr>
</table>
<table width='31%' height="103" align='center'>
<tr>
<td>
<a href='index.php'>Home</a><br>
<a href="index.php?page=login">Login</a>
<a href="index.php?page=videos1">vedios</a>
<a href="index.php?page=s">sknoelege</a>
</td>
<td width='80%'> <body bgcolor='#9999CC'>

     <form action='login.php' method='POST'>
           username: <input type='text' name='username'><br>
            password:<input type='password' name='password'><br>
            <input type='submit' value='Login'>
  </form>
</body>
<td width="70%"

<?php
$section ="inc";
$page = $_GET ["page"];

if ($page)
{
	
	//check for sections
	if (!$section)
	$section="inc";
}
$path= $section."/".$page.".php";

if (file_exists($path))

{
include($path);
}

else
{
echo "Sorry that Page doesnt exist.";
}

?>
</td>
</tr>
</table>
</html>

thanks for the continious support and encouragment

0

I'm afraid I didn't understand any of your reply, but looking over your code again I think I understand what you are trying to do.

It seems that $_GET is only set if the user has already clicked on one of the links (lines 16 to 19).

Try using the following code (replace lines 31 to 55)

<?php
$section ="inc";

if (isset($_GET['page']) && isset($section))
{
	$page = $_GET['page'];
	$path = $section . "/" . $page . ".php";
	if (file_exists($path))
	{
		include($path);
	}
	else
	{
		echo "Sorry that Page doesnt exist.";
	}
}
?>

Zagga

Edited by Zagga: n/a

0

I'm afraid I didn't understand any of your reply, but looking over your code again I think I understand what you are trying to do.

It seems that $_GET is only set if the user has already clicked on one of the links (lines 16 to 19).

Try using the following code (replace lines 31 to 55)

<?php
$section ="inc";

if (isset($_GET['page']) && isset($section))
{
	$page = $_GET['page'];
	$path = $section . "/" . $page . ".php";
	if (file_exists($path))
	{
		include($path);
	}
	else
	{
		echo "Sorry that Page doesnt exist.";
	}
}
?>

Zagga

Morning!
the code you have written and mycode has same results it works for other pages but your codedoes not show any error for :home: page while as mine does

thanks
masudi

0

Good morning masudi,

The code you wrote is very similar to mine, I just put it in the correct order to prevent the error messages you had.

Please mark the thread "solved" if we have sorted out your problem.

Zagga

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.