Sessions not working... I think
Posted: Mon Apr 04, 2011 5:34 pm
I know that that means I probably forgot a ; or } somewhere but I can't seem to find it anywhere in there. Can someone please take a glance at this and see if you can see what I'm missing, please. My eyes and head hurt from staring at the screen for days writing this stuff and it sometimes helps to have a spare set of eyes look at it. So without further adu, here's the code...
Thank you in advance for any help.
Code: Select all
<?php
session_start();
require("config.php");
$con = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Unable to connect to db: " .mysql_error());
$sel = mysql_select_db(DATABASE) or die("Unable to select database: " .mysql_error());
$errors = array();
if($_POST['username'] == '') {
$errors[] = "You forgot to enter a username";
}
if($_POST['password'] == '') {
$errors[] = "You forgot to enter a password";
}
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$username = clean($_POST['username']);
$pass = clean($_POST['password']);
$password = md5($pass);
$query = mysql_query("SELECT * FROM users WHERE username='$username' and pass='$password'");
if(!$query) {
$errors[] = "Could not SELECT from the database: " .mysql_error();
}
if(empty($errors)) {
$num = mysql_num_rows($query);
if($num > 0) {
$member = mysql_fetch_assoc($query);
$_SESSION['username'] = $member['username'];
$_SESSION['first_name'] = $member['first_name'];
header("location: member-home.php");
exit();
} else {
echo "Sorry but that username is not registered with our system<br />";
echo "Please use <a href='register.php'>this</a> form to register";
echo "<br /> Or go back and input a registered username";
}
} else {
echo "Please go back and fix the following errors:<br />";
foreach($errors as $msg) {
echo " - " .$msg. "<br />";
}
?>