php login script works locally but not on host

marcocanary

New Member
\[code\]<?php session_start();include 'db.php';if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['email'])) { header("location:profile.php");} elseif(!empty($_POST['email']) && !empty($_POST['pass'])) { $email = mysql_real_escape_string($_POST['email']); $pass = md5(mysql_real_escape_string($_POST['pass'])); $sql = mysql_query("SELECT id, name, email, pass FROM users WHERE email='$email' AND pass='$pass'"); $row = mysql_fetch_array($sql); $id = $row['id']; $email1 = $row['email']; $name = $row['name']; $num = mysql_num_rows($sql); if($num == 1) { $_SESSION['id'] = $id; $_SESSION['email'] = $email1; $_SESSION['name'] = $name; $_SESSION['LoggedIn'] = 1; $update = mysql_query("UPDATE users SET lastlogin=NOW() WHERE email='$email1'"); header("location:profile.php"); } else { echo "<h1>Error</h1>"; echo "<p>Sorry! Either your account could not be found or you have entered the wrong email or password. Please try again.</p>"; }}?>\[/code\]This script works perfectly in my localhost environment but when uploaded to host, it does not go to the profile.php after logging in. Also, it doesn't redirect to profile.php if the session is set or not empty. Any ideas?And second question, is my code correct for updating the 'lastlogin' to the current time? What does the database structure have to be for this? It is not updating in my database.Thank you for your help.
 
Top