helpmeplease2 Posted May 21, 2006 Share Posted May 21, 2006 Using a username and password that I have in my database returns the error:[code]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/public_html/includes/logincheck.php on line 10Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/includes/logincheck.php on line 11Invalid Username![/code]I know the username and password are correct, so whats wrong? Here are my files:index.php:[code]<?php session_start();header("Cache-Control: private");require('config.php');require('includes/dbconnect.php');?><html><head><?phprequire('includes/logincheck.php');?></head><body><?phpif(isset($_SESSION['Username']) && isset($_SESSION['Password'])){include('includes/topusercp.php'); //this file just has the navigation i want to display once the user is logged in}else{include('includes/topmain.php'); //this is the navigation before the user is logged in}?><?php$p="includes/" . $_GET['p'] . ".php";if($_GET['p']==''){$p="includes/main.php"; /this is the page with the login fields}include($p);?></body></html>[/code]logincheck.php:[code]<?phpif($_GET['logout']=='y'){session_unset(); }if(empty($_SESSION['Username'])){if(($_POST['Username']!='') && ($_POST['Password']!='')){$tmpusr=$_POST['Username'];$results=mysql_query("select Username,Password,ban from $month where Username='$tmpusr'");$row=mysql_fetch_assoc($results);if (mysql_num_rows($results)==0) {echo "Invalid Username!";}elseif($row['Password']!=$_POST['Password']){echo "Invalid Password!";}else{if($row['ban']>0){echo "Your account has been suspended or banned!";}else{$Username=$_POST['Username'];$Password=$_POST['Password'];session_register("Username");session_register("Password");$Username=$_SESSION['Username'];$Password=$_SESSION['Password'];}}}}else{$Username=$_SESSION['Username'];$Password=$_SESSION['Password'];}?>[/code]main.php:[code]<form action="index.php" method="post" style="padding:0px; margin:0px"><table border="0"><tr><td width="60"><div class="smplan2" align="left"><b>Username:</b></div></td><td><input class="searchf" type="text" name="Username" size="20"></td></tr><tr><td><div class="smplan2" align="left"><b>Password:</b></div></td><td><input class="searchf" type="password" name="Password" size="20"><button type="submit" class="buttons">Login</button>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10151-sessions/ Share on other sites More sharing options...
.josh Posted May 22, 2006 Share Posted May 22, 2006 you haven't opened a database connection to run your query in your logincheck.php. you need to throw require('includes/dbconnect.php');in there up there (assuming that dbconnect.php is your db connection script, and that it works properly) Quote Link to comment https://forums.phpfreaks.com/topic/10151-sessions/#findComment-37824 Share on other sites More sharing options...
helpmeplease2 Posted May 22, 2006 Author Share Posted May 22, 2006 That didn't work. I have already made a connection to the database in the index.php file. Quote Link to comment https://forums.phpfreaks.com/topic/10151-sessions/#findComment-37827 Share on other sites More sharing options...
.josh Posted May 22, 2006 Share Posted May 22, 2006 umm.. so? just cuz you did it on one page doesn't mean it automatically stays open and available for use on your other pages. Things don't pass from page to page automatically like that. Did you even try? And if you did, what do you mean by "it doesn't work." I'm sorry, but i don't remember what that error message means. I couldn't find it in the php manual list. Quote Link to comment https://forums.phpfreaks.com/topic/10151-sessions/#findComment-37831 Share on other sites More sharing options...
trq Posted May 22, 2006 Share Posted May 22, 2006 Your not checking your query succeeded before trying to use it.[code]if ($results=mysql_query("select Username,Password,ban from $month where Username='$tmpusr'")) { $row = mysql_fetch_assoc($results); // rest of code.} else { echo mysql_error();}[/code]PS: your query is more than likely failing. Where do you define $month? Quote Link to comment https://forums.phpfreaks.com/topic/10151-sessions/#findComment-37832 Share on other sites More sharing options...
helpmeplease2 Posted May 22, 2006 Author Share Posted May 22, 2006 [!--quoteo(post=375916:date=May 21 2006, 07:28 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 21 2006, 07:28 PM) [snapback]375916[/snapback][/div][div class=\'quotemain\'][!--quotec--]umm.. so? just cuz you did it on one page doesn't mean it automatically stays open and available for use on your other pages. Things don't pass from page to page automatically like that. Did you even try? And if you did, what do you mean by "it doesn't work." I'm sorry, but i don't remember what that error message means. I couldn't find it in the php manual list.[/quote]I did try it and it gave me the same error message as I was getting before, thus "it doesn't work".[!--quoteo(post=375917:date=May 21 2006, 07:29 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ May 21 2006, 07:29 PM) [snapback]375917[/snapback][/div][div class=\'quotemain\'][!--quotec--]Your not checking your query succeeded before trying to use it.[code]if ($results=mysql_query("select Username,Password,ban from $month where Username='$tmpusr'")) { $row = mysql_fetch_assoc($results); // rest of code.} else { echo mysql_error();}[/code]PS: your query is more than likely failing. Where do you define $month?[/quote]$month is defined in config.php which also has the database details.I tried inserting the echo mysql_error but I can't find where to put it I get unexpected t_string errors. Could you tell me where in the code to place that? Quote Link to comment https://forums.phpfreaks.com/topic/10151-sessions/#findComment-37851 Share on other sites More sharing options...
.josh Posted May 22, 2006 Share Posted May 22, 2006 maybe if you posted what the error actually says we can help you better. continually saying "it doesn't work" means nothing. obviously it doesn't work, otherwise you wouldn't be here. Quote Link to comment https://forums.phpfreaks.com/topic/10151-sessions/#findComment-37852 Share on other sites More sharing options...
helpmeplease2 Posted May 22, 2006 Author Share Posted May 22, 2006 I think there was a problem that it wasn't reading the $month because I reuploaded everything and its working now. Sorry to waste your time [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] One more question. Once the user logs in they see the content that is on main.php which still has the login box, how can I make it so once they login they see home.php instead?I know this works, but then it makes me have the content from main.php displaying aswell as the content from home.php I just want home.php.[code]<?phpif(isset($_SESSION['Username']) && isset($_SESSION['Password'])){include('includes/home.php');}else{include('includes/main.php');}?>[/code]Help? Quote Link to comment https://forums.phpfreaks.com/topic/10151-sessions/#findComment-37854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.