hungryhobo14 Posted July 21, 2007 Share Posted July 21, 2007 I am trying to get a log on script up. so far I have successfully added the user to the database and i see it in my sql admin thing and everything. when I go to log on, nothing happens. it does the same thing weather the name is right or wrong. what is wrong? <?php $db_name = "chrmer3_first"; $db_user = "chrmer3_first"; $db_pass = "***"; $db_host = "mysql3.freehostia.com"; mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name) or die(mysql_error()); session_start(); $username = $_POST[‘username’]; $password = $_POST[‘password’]; $query = 'select * from users where username = "username" and password="$password"'; $result = mysql_query($query); if (mysql_num_rows($result) != 1) { $error = 'Bad Login'; include 'login.html'; } else { $_SESSION[‘username’] = "$username"; include "memberspage.php"; } ?> Quote Link to comment Share on other sites More sharing options...
DeadEvil Posted July 21, 2007 Share Posted July 21, 2007 Much better.. <?php session_start(); $db_name = "chrmer3_first"; $db_user = "chrmer3_first"; $db_pass = "***"; $db_host = "mysql3.freehostia.com"; mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name) or die(mysql_error()); $query = mysql_query("select * from users where username = '{$_POST['username']}' and password='{$_POST['password']}'"); $row = mysql_num_rows($query); if ($row == 0) { $error = 'Bad Login'; header('location: login.html'); } else { $_SESSION['username'] = $_POST['username']; header('location: memberspage.php'); } ?> Quote Link to comment Share on other sites More sharing options...
hungryhobo14 Posted July 21, 2007 Author Share Posted July 21, 2007 Thanks I got that working now but I have another question. How can I make it so that you need to be logged in to view the page? and not just go straight to it? Quote Link to comment Share on other sites More sharing options...
DeadEvil Posted July 23, 2007 Share Posted July 23, 2007 require this code inside the memberspage.php.. #check.php if (empty($_SESSION['username'])): header('location: login.html?'.msg="You need to login to access this page!!!"); exit(); endif; ex: #memberspage.php require_once 'check.php'; .... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.