Login Script
Code: Select all
<?php
// Connect to MySQL
$conn = mysql_connect("dbserver", "dbuser", "dbpass") or die ("Cannot connect to mysql server");
mysql_select_db("dbname", $conn) or die ("Cannot connect to mysql database");
// Note, this script is a seperate page that is being posted to with a username and a password
// Variables
$username = $_POST['username'];
$password = $_POST['password'];
// Check form against database
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysql_query($sql, $conn) or die ("Cannot execute query");
$rows = mysql_num_rows($result);
if ($rows == "0") {
// If results didn't match the database
?>
<div align="left">
Your uisername and password are incorrect<br>
<a href="index.php" target="_self">Continue</a>
</div>
<?php
}
else {
// If results did match the database
// Set cookie or session
header("Location:index.php");
}
?>Code: Select all
<?php
// Connect to MySQL
$conn = mysql_connect("dbserver", "dbuser", "dbpass") or die ("Cannot connect to mysql server");
mysql_select_db("dbname", $conn) or die ("Cannot connect to mysql database");
// Note, this script is a seperate page that is being posted to with a username and a password and other stuff
// Variables
$username = $_POST['username'];
$password = $_POST['password'];
$other_stuff = $_POST['other'];
// Insert Results
// MORE TO COME!
?>