PDA

View Full Version : Login Help


chris_burns7186
09-10-2010, 01:01 PM
I'm completing the video tutorial for the php log in script and I'm having trouble getting it to work. It keeps returning that my user/password are wrong even though I have checked these. can anyone help?

<?php

///////////////////////////////
$database = "db";
$username = "user";
$password = "password";
///////////////////////////////

// Choose Connection
$link = @mysql_connect($database ,$username, $password);
$db =mysql_select_db($database, $link);

//catch field data
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];

if ($userid && $password) {
///////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM users WHERE user_name = '$userid' AND user_password = '$password'");
$result =@mysql_query($query);
$rowAccount =@mysql_fetch_array($result);
//
}

if($rowAccount) {
echo "Success";
exit;


}elseif($rowAccount){
echo "fail";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="form1" id="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="259" height="272" border="1" align="center">
<tr>
<td width="82" height="45">Username</td>
<td width="161" ><input name="userid" type="text" id="userid" /></td>
</tr>
<tr>
<td width="82" height="45">Password</td>
<td>
<input name="password" type="text" id="password" />

</td>
</tr>
<tr>
<td>
<input name="Submit" type="submit" value="Submit"/>
<input name="submitted" type="hidden" id="submitted" value="1" />
</td>

</tr>
</table>
</form>
</body>
</html>

davidj
09-13-2010, 06:18 PM
check your database table field naming conventions

krzy
10-23-2013, 08:17 PM
user and user_name aren't the same :razz:

global2017
11-02-2017, 08:28 AM
artikel bagus

edbr
11-03-2017, 02:35 AM
Tidak Bagus. No not good. 7 year old post and mysql is depreciated so pretty useless now