Jump to content

[SOLVED] Quick Database question


shatteredcode

Recommended Posts

I'm trying to set up a login script with the users coming form a database. I can't, however, seem to extract that information. What's wrong with my script?

<?php

INCLUDE "connect.php";

$host = "host";
$database = "database";
$user = "user";                                     // I changed these for the post, they're right in my script
$pass = "pass";

ConnectToDatabase($database, $user, $pass, $host);

/**********/
//Select our table.
$query = "SELECT user, pass FROM users";
//Query the table (Get the information from it.)
$result = mysql_query($query);

//Extracts the array from the table	
$row = mysql_fetch_array($result);

$database_user == $row['user'];
echo ($database_user);
print "hello, why don't you login? <br />";
  ?>
  
<!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>Login</title>
</head>

<body>
<form id="login" name="login" method="post" action="login.php">
  <label>
  User
  <input type="text" name="user" id="user" />
  </label>
  <p>
  Password
    <input type="password" name="pass" id = "pass"  />
</p>
  <input type="submit" id="submit" name="sumbit" />
</form> 
</body>
</html>


<?php

if ($typed_user == $database_user)
{
echo('Worked!');
}
else {
echo(' Didn\'t Work!');
}

?>

 

I'm not sure of my error.

BTW: I'm only checking the user right now, not the password. This is just a test.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/107265-solved-quick-database-question/
Share on other sites

<?php

INCLUDE "connect.php";

$host = "host";
$database = "database";
$user = "user";
// I changed these for the post, they're right in my script
$pass = "pass";

ConnectToDatabase($database, $user, $pass, $host);

$query = "SELECT user, pass FROM users WHERE `user` = '$typed_user'";
$result = mysql_query($query);

$row = mysql_fetch_array($result);

$database_user == $row['user'];
echo($database_user);
print "hello, why don't you login? <br />";
?>

<!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>Login</title>
</head>

<body>
<form id="login" name="login" method="post" action="login.php">
<label>
User
<input type="text" name="user" id="user" />
</label>
<p>
Password
<input type="password" name="pass" id = "pass"  />
</p>
<input type="submit" id="submit" name="sumbit" />
</form>
</body>
</html>


<?php
if ($typed_user == $database_user) {
    echo('Worked!');
} else {
    echo(' Didn\'t Work!');
}
?>

$query = "SELECT user, pass FROM users WHERE `user` = '$typed_user'";

 

$typed_user has not been defined. You need to get it from the posted data.

 

$database_user == $row['user'];

 

to assign a value, use "=" and not the comparison operator "=="

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.