Jump to content

sessions


helpmeplease2

Recommended Posts

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 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![/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>
<?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>[/code]

logincheck.php:
[code]<?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'];
}
?>[/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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

[!--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?
Link to comment
Share on other sites

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

Help?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.