Hey everyone,

I'm sorry for re-opening this again but I have a log in script that someone gave me on here and it works on my local server..but when I upload it to godaddy..it doesn't work right..it keeps saying my user info isn't correct when It clearly is..and It's connected to the database correctly as well as the table..I don't know what to do..

Here is the log in script with the login form because it is all on the same page..

<?php
// script login for login.php
session_start();
$err='';
$file=strip_tags($_SERVER['PHP_SELF']);

if(isset($_POST['Submit']))
{
	//connect to login database
	mysql_connect('******','********','*******') or die(mysql_error());
	mysql_select_db('*********') or die(mysql_error());



	$user = mysql_real_escape_string(stripslashes($_POST['username']));
	$pass = mysql_real_escape_string(stripslashes($_POST['password']));

	$select = "SELECT * FROM `users` where `username`='".$_POST['username']."' AND `password`='".md5($_POST['password'])."'";
	$msq = mysql_query($select) or die(mysql_error());
	$total=mysql_num_rows($msq);
	if(1==$total)
	{
		$row = mysql_fetch_assoc($msq);
		foreach($row as $k=>$v)
		{
			$_SESSION[$k] = $v;
		}
	
		if(isset($_SESSION['returnTo']) && !empty($_SESSION['returnTo']))
		{
			$temp=$_SESSION['returnTo'];
			$_SESSION['returnTo']=NULL;
			header('Location: '.$temp);
		}
		elseif(1==(int)$_SESSION['user_level'])
		{
			header('Location: Blog-admin-area.php');
		}
		else
		{
			header('Location: index.php');		
		}
		exit;
	}
	elseif(0==$total)
	{
		$err='<p>Incorrect username/password</p>';
	}
	else
	{
		$err='<p>We are currently experiencing technical difficulties.  Please try again later.</p>';

		$msg='Error encountered at '.$file.'.  Expected the query to yield zero or one row, but instead the query generated '.$total.' rows.'.PHP_EOL;
		$msg.='The submitted data is as follows:'.PHP_EOL.print_r($_POST,true);

		$webmaster='***********.com';
		$to=$webmaster;

		$subject="Error at Login Page For Ready Or Not Tahirih's website";

		$headers='To: '.$to.PHP_EOL;
		$headers.='From: '.$webmaster.PHP_EOL;
		$headers.='Return-Path: '.$webmaster.PHP_EOL;
		
		mail($to,$subject,$msg,$headers);
	}
}
?>

and here is the html form

<?php
if(!empty($err))
{
	echo $err;
}
?>
<form action="<?php echo $file;?>" method="post">
  <table width="50%" border="0" align="center" cellpadding="7" cellspacing="0">
    <tr> 
      <td width="22%">Username</td>
      <td width="78%"><input name="username" type="text" id="username"></td>
    </tr>
    <tr> 
      <td>Password</td>
      <td><input name="password" type="password" id="password"></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
  <div class="login-links">
	<a href="lost_pw.html">Lost Password</a>   <a href="changepassword-form.php"> Change Password</a>
	</div>
</form>

Thanks for bearing with me!! I appreciate everyone's help!

Script looks fine. If I have difficulties when I put a script online it is mostly because of these two reasons:

>> The database is not the same as the local one (this is the most probable cause in your case)
>> I forgot to upload another essential file
>> There is an unknown absolute path

Hope this helps :) I think your database doesn't have a record of user '****' with password hash "jdioafu928749820480fa890'(or something like that).

~G

@grafix, ok..I thought the script looked fine to me..and I reconnected the database to the one located on the goddady phpmyadmin that I set up..so that shouldn't be the issue..and I made triple sure that there wasn't an extra file or an unknown path..do I need to talk to a godaddy person?

The problem isn't that your database isn't connected, but that the database does not have the same data as your local one.

For example there is a user 'jack' in the local database, but not in the hosted database. Or the passwords are not the same.

There is nothing wrong with the script.

~G

@Graphix, But how is this possible? I've got the same database for both places..same set up..same everything...so I am wondering if I need to rewrite this script with the same idea in mind..I contacted godaddy and I am waiting on a response but there has got to be another way to rewrite the script to fit the same purpose that goddays server will work with..

Hmm... I really thought the problem would lay there.

If that isn't the issue, I can't really give you a straight solution, you will first need to debug the code and check whether everything is received correctly and compared correctly:

$user = mysql_real_escape_string(stripslashes($_POST['username']));
$pass = mysql_real_escape_string(stripslashes($_POST['password']));

echo "Received form values: user='".$user."', pass='".$pass."'<br />";

// You retrieved the form values already, no need to retrieve them again: use the existing variables
$select = "SELECT * FROM `users` where `username`='".$user."' AND `password`='".md5($pass)."'";

echo "Query: '".$select."'<br />";

$msq = mysql_query($select) or die(mysql_error());

$total=mysql_num_rows($msq);

echo "Total: '".$total."'<br />";

This HAS to provide you the solution, as there isn't anything obvious wrong with the script (except some neglected comments and white-spacing).

Make sure that the user and the MD5-HASHED password correspond with the entry in the database (now I come to think of it, have you entered the md5 hash of the password into the row?)

~G

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.