Jump to content


Photo

PHP easy help please


  • Please log in to reply
5 replies to this topic

#1 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 07 August 2006 - 10:57 PM

this should be simple
i just wanted to know what was wrong for the following code

<?php
//replace username and password with your mysql name and password
$conn = mysql_connect("*******","*****","*****");

//select the database
$db = mysql_select_db("*******");

$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];

$result = MYSQL_QUERY("SELECT * from registration WHERE username='$username' and password='$password'")
   or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

$username = $worked[username];
$password = $worked[password];
$email = $worked[email];

if($worked){
echo "<a href=\"#\" class=\"menu\">Home</a>-
<a href=\"#\" class=\"menu\">Learn HTML</a>-
<a href=\"#\" class=\"menu\">Learn CSS</a>-
<a href=\"#\" class=\"menu\">Learn PHP</a>-
<a href=\"#\" class=\"menu\">About Us</a>-
<a href=\"#\" class=\"menu\">FAQ's</a>";}

else{
echo "<a href=\"#\" class=\"menu\">Home</a>-
<a href=\"register.php\" class=\"menu\">Register</a>-
<a href=\"login.php\" class=\"menu\">Login In</a>-
<a href=\"#\" class=\"menu\">About Us</a>-
<a href=\"#\" class=\"menu\">FAQ's</a>";}
?>


#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 07 August 2006 - 10:59 PM

And the error you are getting is?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 07 August 2006 - 11:00 PM

when the user is logged in i want a specific menu to appear
but when they are not logged in i want another menu to appear

but even when i logg in the same menu is always showing
which is the one which is not logged in

#4 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 07 August 2006 - 11:03 PM

if($worked){
echo "<a href=\"#\" class=\"menu\">Home</a>-
<a href=\"#\" class=\"menu\">Learn HTML</a>-
<a href=\"#\" class=\"menu\">Learn CSS</a>-
<a href=\"#\" class=\"menu\">Learn PHP</a>-
<a href=\"#\" class=\"menu\">About Us</a>-
<a href=\"#\" class=\"menu\">FAQ's</a>";}

else{
echo "<a href=\"#\" class=\"menu\">Home</a>-
<a href=\"register.php\" class=\"menu\">Register</a>-
<a href=\"login.php\" class=\"menu\">Login In</a>-
<a href=\"#\" class=\"menu\">About Us</a>-
<a href=\"#\" class=\"menu\">FAQ's</a>";

this is the part that is not working

#5 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 07 August 2006 - 11:08 PM

The problem is with your logic here
$result = MYSQL_QUERY("SELECT * from registration WHERE username='$username' and password='$password'")
   or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

The query would only fail if there was an error, not if the matching name and password were not found.  The query might easily work but not return any matched rows. So you need to count how many rows were returned, if it was none then the username and password have no match.

$result = MYSQL_QUERY("SELECT * from registration WHERE username='$username' and password='$password'")
   or die ("Name and password not found or not matched");

$numofrows = mysql_num_rows($result);

$worked = mysql_fetch_array($result);

if($numofrows == 0)
{
     // no match found
}

Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#6 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 07 August 2006 - 11:11 PM

it worked
thank you so much




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users