Jump to content


Photo

sessions


  • Please log in to reply
7 replies to this topic

#1 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 21 May 2006 - 11:53 PM

Using a username and password that I have in my database returns the error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/public_html/includes/logincheck.php on line 10

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/includes/logincheck.php on line 11
Invalid Username!

I know the username and password are correct, so whats wrong? Here are my files:

index.php:
<?php 
session_start();
header("Cache-Control: private");
require('config.php');
require('includes/dbconnect.php');
?>
<html>
<head>
<?php
require('includes/logincheck.php');
?>
</head>
<body>
<?php
if(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>

logincheck.php:
<?php
if($_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'];
}
?>

main.php:
<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>


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 May 2006 - 12:04 AM

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)
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 22 May 2006 - 12:15 AM

That didn't work. I have already made a connection to the database in the index.php file.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 May 2006 - 12:28 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 May 2006 - 12:29 AM

Your not checking your query succeeded before trying to use it.
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();
}
PS: your query is more than likely failing. Where do you define $month?

#6 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 22 May 2006 - 01:49 AM

[!--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) View Post[/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) View Post[/div][div class=\'quotemain\'][!--quotec--]
Your not checking your query succeeded before trying to use it.
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();
}
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?

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 May 2006 - 01:54 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 22 May 2006 - 02:03 AM

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.
<?php
if(isset($_SESSION['Username']) && isset($_SESSION['Password'])){
include('includes/home.php');
}else{
include('includes/main.php');
}
?>

Help?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users