I'm very new to PHP and MySQL, I've read one of these books for absolute beginners and I'm currently trying to code a character database for a chat-based game.
So if you hear from me a lot, that's why.
Now, I have created the database Test in MySQL, this contains the table login. The table has four fields:
id - int(11) - PRI
username - varchar(20)
password - varchar(10)
st - enum('TRUE', 'FALSE')
Where ST is a special kind of user with administrative privaliges.
I've then added two records to the database:
- id=0 , username=storyteller , password=st , st=TRUE
- id=1 , username=player , password=player , st=FALSE
Then I made a HTML form for the user to enter their username and password, and a PHP form which will then check that username and password against the records stored on the database.
It's this PHP form that I'm having trouble with as the book I learnt from gave me little to no information on retrieving singluar variables from a database without printing the whole lot out.
So far, this is what I have:
<HTML>
<HEAD>
<TITLE>Test Login</TITLE>
</HEAD>
<BODY>
<?
//pulls the username and password from the previous form
$user = $_REQUEST["user"];
$pass = $_REQUEST["pass"];
//makes the connection to the database
$conn = mysql_connect("localhost", "hollowd_roses", "*******");
mysql_select_db("hollowd_Test", $conn);
//creates a username query
$sql = "SELECT * FROM Login where $user == username";
$result = mysql_query($sql);
//HERE IS WHERE I'M STUCK, AS I'M NOT SURE HOW TO PULL THE PASSWORD RELATING TO THAT SPECIFIC USER FROM THE DATABASE
//checks password against database
if ($pass == $password){
PRINT "You are Logged In";
} else {
PRINT "Password not recognised";
} // end if
?>
</BODY>
</HTML>
I've highlighted the area I'm struggling with, with that big ass comment in caps.
Currenly if I run it as it is, I get 'Password not recognised' no matter what I type in, that's probably because I have no code in there to pull the password variable from the database 😃
If you need any more info from me then I'm happy to explain as far as I can.
Thanks in advance for your help.