Jump to content

[SOLVED] trouble with login


jbingman

Recommended Posts

Hey im still having trouble with a login page http://www.fresnosar.com/php/login.php.

when i enter the login in username and password, the database is connected but nothing happens. it tells me that the login failed. but everything seems to be in working order. heres my login and dbconnect script.

login.php

<? session_start(); ?>
<?
// dBase file
include ("dbConfig.php");

if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
	{
	die("You need to provide a username and password.");
	}

// Create query
$q = "SELECT * FROM `dbUser` "
	."WHERE `username`='".$_POST["username"]."' "
	."AND `password`=PASSWORD('".$_POST["password"]."') "
	."LIMIT 1";
// Run query
$r = mysql_query($q);

if ( $obj = @mysql_fetch_object($r) )
	{
	// Login good, create session variables
	$_SESSION["valid_id"] = $obj->id;
	$_SESSION["valid_user"] = $_POST["username"];
	$_SESSION["valid_time"] = time();

	// Redirect to member page
	Header("Location: member.php");
	}
else
	{
	// Login not successful
	die("Sorry, could not log you in. Wrong login information.");
	}
}
else
{
echo "<form action=\"?op=login\" method=\"post\">";
echo "<table cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"146\" height=\"16\" colspan=\"2\"><div style=\"color:#FFFFFF; font-size:14px; white-space:2px; border-bottom:#000000 thin solid; border-top:#000000 thick solid\">FresnoSAR Login</div></td>";
echo "</tr><tr>";
echo "<td align=\"left\" style=\"border:#000000 thin solid\">";
echo "<div style=\"color:#FFFFFF; font-size:11px; white-space:2px\">Username:<br />";
echo "<input name=\"username\" id=\"username\" width=\"140\"/>  </div> </td>";
echo "</tr><tr>";
echo "<td align=\"left\" style=\"border:#000000 thin solid\"><div style=\"color:#FFFFFF; font-size:11px; white-space:2px\">Password:<br />";
echo "<input type=\"password\" name=\"password\" width=\"140\" /></div></td>";
echo "</tr><tr>";
echo "<td height=\"25\" colspan=\"2\" align=\"center\" style=\"border:#000000 thin solid\"><input type=\"submit\" name=\"login\" value=\"Login\" />";
echo"</table></form>";
}
?>

dbConfig.php

<?
$host = "localhost";
$user = "*myusername*";
$pass = "*mypassword*";
$db   = "dbUser";

// This part sets up the connection to the 
// database (so you don't need to reopen the connection
// again on the same page).
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}

// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>

 

Link to comment
Share on other sites

Firstly, do not use the mysql PASSWORD function for encryption. Is it not intended to be used by client code and is liekly to brake your application in the future. Read the manual for more details.

 

Secondly, you never check your query succeeds before using it. At minimum you need....

 

$r = mysql_query($q) or die(mysql_error();

Link to comment
Share on other sites

The book in my signiture will teach you php from the ground up. If its just login tutoirlas your after, you might try the phpfreaks.com site itself, otherwise you'll need to google for them. I haven't done a tutorial in years so can't really recommend any.

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.