Jump to content

log on not working.


hungryhobo14

Recommended Posts

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";
}

?>

Link to comment
Share on other sites

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');
}
?>

Link to comment
Share on other sites

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';
....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.