i wrote a lign script for my site but it doesn't seem to work.even if i type in the correct username and password, i get a message saying tht what i typed in was wrong.
| Code: |
|
<?php // database connection details $mysql_host = "localhost"; # The mysql host, can usually be left as localhost. $mysql_user = ""; # The username we will use to connect to mysql $mysql_pass = ""; # The password that the above username relates to $db = ""; # The name of the database the above user has privledges on //connect to the database $conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass); if(!$conn) { exit("<strong>Error!</strong> Could not <u>connect</u> to the database!"); } $db_conn = mysql_select_db($db, $conn); if(!$db_conn) { exit("<strong>Error!</strong> Could not <u>select</u> the database!"); } $sql = mysql_query("SELECT * FROM students WHERE username='".addslashes($_POST['user'])."'") or die ("Username was incorrect. MySQL said".mysql_error()); $result = mysql_fetch_array($sql); // puts the database information into an array if($result['password'] == sha1($_POST['pass'])) { // if the passwords match session_start(); // start the session header("Cache-control: private"); $_SESSION["sessioname"] = $_POST['user']; header("location: index.php"); }else{ echo "Incorrect login details please try again."; } ?> |
