perezf Posted August 7, 2006 Share Posted August 7, 2006 this should be simplei just wanted to know what was wrong for the following code[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>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/16843-php-easy-help-please/ Share on other sites More sharing options...
king arthur Posted August 7, 2006 Share Posted August 7, 2006 And the error you are getting is? Link to comment https://forums.phpfreaks.com/topic/16843-php-easy-help-please/#findComment-70877 Share on other sites More sharing options...
perezf Posted August 7, 2006 Author Share Posted August 7, 2006 when the user is logged in i want a specific menu to appearbut when they are not logged in i want another menu to appearbut even when i logg in the same menu is always showingwhich is the one which is not logged in Link to comment https://forums.phpfreaks.com/topic/16843-php-easy-help-please/#findComment-70881 Share on other sites More sharing options...
perezf Posted August 7, 2006 Author Share Posted August 7, 2006 [code]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>";[/code]this is the part that is not working Link to comment https://forums.phpfreaks.com/topic/16843-php-easy-help-please/#findComment-70884 Share on other sites More sharing options...
king arthur Posted August 7, 2006 Share Posted August 7, 2006 The problem is with your logic here[code]$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);[/code]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.[code]$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}[/code] Link to comment https://forums.phpfreaks.com/topic/16843-php-easy-help-please/#findComment-70885 Share on other sites More sharing options...
perezf Posted August 7, 2006 Author Share Posted August 7, 2006 it workedthank you so much Link to comment https://forums.phpfreaks.com/topic/16843-php-easy-help-please/#findComment-70886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.