Page 1 of 1

login problems

Posted: Sun Aug 16, 2009 7:11 am
by camster
I recently switched my hosting of my php/mysql website. I successfully recreated and connected the database on the new hosting, all the data for members is displaying, and I'm able to login to my Super Admin. It appears everything is working fine except the login for members keeps coming up as wrong username or password even though I am sure it's been correct. I really have no idea where to pinpoint the problem so thought I would show the code for the login page here and maybe someone can direct me to where I should look. Any help would be great!

Thanks
Camster

Code: Select all

<?php
session_start();
if($_SESSION['AUTH']=="OK")
{
   header("Location:addIntro.php");
      exit;
}
$submit=$_POST['Signin'];
$uid=$_POST['userid'];
$password=$_POST['password'];
$mesg="";
//echo "<pre>";
//print_r($_POST);
 
if($submit)
{
   include "../connections/db.php";
   $sql="select GID from golfer where UserId='$uid' and UserPwd='$password'";
   echo $sql;
   $conn=mysql_query($sql);
   $rowscnt=mysql_num_rows($conn);
   if($rowscnt!=0)
   {
      $resc=mysql_fetch_object($conn);
      $_SESSION['GID']=$resc->GID;
      $_SESSION['USER']=$uid;
      $_SESSION['AUTH']="OK";
      header("Location:addIntro.php");
      //echo "done";
      exit;
   }
   else
   {
      //echo "whats wrong";
      $mesg= "The User ID or Password is incorrect. Please retype the User ID and Password";
   }
}
 
?>
Any suggestions on how to check for the problem would be great.

Thanks

Re: login problems

Posted: Sun Aug 16, 2009 12:25 pm
by califdon
Start by displaying any MySQL errors that may occur. Change your code to:

Code: Select all

$conn=mysql_query($sql) or die(mysql_error());
$rowscnt=mysql_num_rows($conn) or die(mysql_error());

Re: login problems

Posted: Tue Sep 01, 2009 9:45 am
by camster
thanks Califdon. I replaced the code as suggested and it outputs the same message as before.

select GID from golfer where UserId='cam' and UserPwd='dbPassword'

User password should be from the members table not the actual db password

note: I have replaced the actual database password with "dbPassword"

Thanks

Re: login problems

Posted: Tue Sep 01, 2009 12:40 pm
by requinix
Didn't you get your answer in your second thread?

Re: login problems

Posted: Tue Sep 01, 2009 8:27 pm
by camster
"Lemme guess: you use a $password variable in your connections/db.php?

That value is overwriting the one you got from the form."

In a way I did, I'm just not sure how to go about fixing it.


Sorry about the other post, I originally never recieved any replies so reposted. I've left a reply at the other post directing to this one.

Thanks

Re: login problems

Posted: Tue Sep 01, 2009 10:19 pm
by requinix
Change the variable to be something else. Or use constants instead.

Whatever, so long as you don't have two different $password variables floating around.

Re: login problems

Posted: Wed Sep 02, 2009 9:45 am
by camster
Made some progress, I changed the database password variable name to dbpassword (hopefully I can do that) in the connections file.
From the message below the users login is now correct but I get another message

select GID from golfer where UserId='cam' and UserPwd='cam' this is correct
Warning: Cannot modify header information - headers already sent by (output started at /my local machine/html/golferscores09/connections/db.php:10) in /home/content/c/a/m/camster77/html/golferscores09/playerAdmin/login.php on line 28
note: I've changed my local machine URL for this thread

line 28 is:
header("Location:addIntro.php");

The addintro.php begins with
<?
include "logincheck.php";
?>

logincheck.php is this
<?
session_start();
//print_r($_SESSION);
$GID=$_SESSION['GID'];
if(!$GID)
{
header("Location:login.php");
exit;
}

?>

I cant find anywhere else where I should change the variable name? Maybe I should try constants instead?

Re: login problems

Posted: Wed Sep 02, 2009 12:49 pm
by requinix
(output started at /my local machine/html/golferscores09/connections/db.php:10)
Make it so that db.php doesn't output anything.

Re: login problems

Posted: Wed Sep 02, 2009 7:35 pm
by camster
interesting thing I just noticed. when I login the warning message comes up (the one in my last post) but if I hit refresh I'm in to the user control panel. Does this indicate something or should I do as you last suggested for the db.php to output nothing?

Thanks

Re: login problems

Posted: Wed Sep 02, 2009 9:02 pm
by requinix
That behavior makes sense.

You should still fix it, otherwise your users will see the error message ;)

Re: login problems

Posted: Fri Sep 04, 2009 8:13 am
by camster
My problem is I'm not sure how to make db.php so it doesnt output anything. I did a search here and google but couldnt find anything relevent. So I tried commenting out the line where the problem is:
//header("Location:addIntro.php");

and that did get rid of the warning message but it still brings up a page with a line of code:
select GID from golfer where UserId='cam' and UserPwd='cam'
then I have to refresh to get in.

Now that I am able to get in to the user account I have been able to check the pages and have several warning messages which all point to the header line of code. If I can get this problem fixed I'm sure it will fix all of these.

header("Location:addIntro.php");

header( 'Location: gameScore.php?gid=' . $gameid ) ;

I checked the location of these pages and they are there within the same directory as the page with the header line. I also tried typing in their full URL but didnt help. Just wondering if there's other steps I can take to solve this.

Thanks

Re: login problems

Posted: Fri Sep 04, 2009 12:05 pm
by califdon
camster wrote:My problem is I'm not sure how to make db.php so it doesnt output anything.
That means that PHP will not send a header(...) to the browser if anything has already been sent, because a header is just that, it must be the first thing sent to the browser ("header"--HEAD--get it?). There cannot be any other headers, any echoes or prints, any HTML prior to the <?php, or even a blank line before the <?php prior to the header(...). The only thing that is allowed in a script before a header is sent is pure PHP code that doesn't send anything to the browser.

Re: login problems

Posted: Sat Sep 05, 2009 7:08 am
by camster
Tried putting the header at the very beginning of the page, no spaces, no breaks before.
<?php
header("Location:addIntro.php");
//echo "done";
exit;
ect. ect.....

The result is I end up with a redirect loop message in my browser???

Re: login problems

Posted: Sat Sep 05, 2009 11:16 am
by califdon
I'm afraid I just can't picture what you are doing. The only way I know to advise you is to post your entire include file, enclosed in

Code: Select all

tags[/i], and at least the relevant part of your main file, [i]also enclosed in tags[/i]. Somehow, you are sending conflicting or inappropriate headers.

In case you are unsure about how to use the

Code: Select all

tags, [i]go back and Edit your original post in this thread, to see how I modified it for you[/i].

Re: login problems

Posted: Sat Sep 05, 2009 7:56 pm
by camster
The main page is the login page In the first post with the die statements added as you suggested.
Sorry I'm not giving you more info, I know my way around php and mysql but am not at a code writing level. This program was left with just a few glitches to fix up. If looking at the program will help to understand what it does you can view it at http://www.golferscores.com

This is the incude connectiions file db.php I've replaced all specific connection info to generic where appropriate.

<?php
$conn=mysql_connect("dbhostname","dbusername","dbpassword");
#$conn=mysql_connect("localhost","root","");
mysql_select_db("golferscore");
#mysql_select_db("golf");
$debug=0;

?>

<?php
//Sample Database Connection Syntax for PHP and MySQL.

//Connect To Database

$hostname="dbhostname";
$username="dbusername";
$dbpassword="dbpassword";
$dbname="dbname";
$usertable="your_tablename";
$yourfield = "your_field";

mysql_connect($hostname,$username, $dbpassword) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname);

# Check If Record Exists

$query = "SELECT * FROM $usertable";

$result = mysql_query($query);

if($result)
{
while($row = mysql_fetch_array($result))
{
$name = $row["$yourfield"];
echo "Name: ".$name."<br>";
}
}
?>