PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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...
<?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 />";
}
?>
Thank you in advance for any help.
Last edited by danwguy on Mon Apr 04, 2011 6:30 pm, edited 1 time in total.
<?php
session_start();
if(isset($_SESSION['username'])) {
echo "You have successfully logged in, congrats.";
} else {
echo "Script not working, check sessions";
}
?>
but I get a page that says "Script not working, check sessions" why would that be? I set the $_SESSION['username'] variable in login-exec page that I posted above, why would it not carry over to this page?
This will print out the array and you can check and make sure the variables are being entered how you want them.
If this looks ok, print out the array on your member-home page
Yep, I used to work for them Ipower. By default the php.ini file does not have a path set for the session_save_path. You should be able to go into your Control Panel under Scripting and Addons and PHP scripting and set the sessions to be stored to a location on your account.