Jump to content

user login template error


amitchugh

Recommended Posts

So then $_SESSION['username'] obviously wasn't set. This is either because you are not calling session_start() at the top of your script or it just wasn't set in a way you expected.

 

And because it isn't set, it messes up the SQL query which is why you get the next error.

 

And the other two errors are likely because you are trying to use the data returned from the query which didn't run.

Link to comment
Share on other sites

As scootstah pointed out, you need to have session_start(); on any page that is going to be using a SESSION.  Update includes.php to have this.

<?php
session_start();
$fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username='".$_SESSION['username']."'"));

Link to comment
Share on other sites

hi drummin,

i did as you say.

still the same error but in line 3. as one line increased by code:

session_start();

 

actually index.php has a code at line 25

<?php include("includes.php");?>

i think index.php calls includes.php.

and index.php has that code at the 2nd line : session_start();

Link to comment
Share on other sites

and index.php has that code at the 2nd line : session_start();

 

Then you don't need it here.

 

Without knowing more about your app we can't really help any further. You are trying to use a session when it hasn't been set. From you example I can wager a guess that you are trying to get data from a logged in user that isn't logged in.

 

I don't know where you are setting the username or how this code is being called.

Link to comment
Share on other sites

Have to read how the program is to be used?  It could be that you start with a login form, which would then set values to session and then you are directed to the index page.  I would suggest following the logic of the program if documentation is not available, before you start modifying things.  Could be you are not using the program as intended.

Link to comment
Share on other sites

index.php

<?

session_start();

include_once"config.php";

if(isset($_POST['login'])){

$username= trim($_POST['username']);

$password = trim($_POST['password']);

if($username == NULL OR $password == NULL){

$final_report.="Please complete both fields";

}else{

$check_user_data = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error());

if(mysql_num_rows($check_user_data) == 0){

$final_report.="This username does not exist";

}else{

$get_user_data = mysql_fetch_array($check_user_data);

if($get_user_data['password'] == $password){

$start_idsess = $_SESSION['username'] = "".$get_user_data['username']."";

$start_passsess = $_SESSION['password'] = "".$get_user_data['password']."";

$final_report.="<meta http-equiv='Refresh' content='0; URL=members.php'/>";

}}}}

    if(isset($_SESSION['username']) && isset($_SESSION['password'])){

  header("Location: members.php");

  }

 

?>

<?php include("includes.php");?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

  <title><?php echo $title ?> | template!</title>

  <meta http-equiv="content-type" content="text/html; charset=utf-8" />

 

  <link rel="stylesheet" href="style.css" type="text/css" />

</head>

<?php include("footer.php");?>

 

includes.php

<?php

$fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username='".$_SESSION['username']."'"));

$title= "template !";  //your site title

$yourdomain="localhost"; //your domain name where script is installed - do not use trailing slash

 

$membername= $fetch_users_data->username; //don't change

$memberpoints=$fetch_users_data->points; //don't change

 

$contactemail = ""; //contact form messages will be sent here

$requestemail = "mail.com"; //request messages will be sent here

?>

 

config.php

<?

ob_start();session_start();

$hostname = "localhost"; //your hostname (normally localhost)

$data_username = "root"; //database username

$data_password = ""; //database password

$data_basename = "chchgh"; //database name

$conn = mysql_connect("".$hostname."","".$data_username."","".$data_password.""); 

mysql_select_db("".$data_basename."") or die(mysql_error()); 

 

?>

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.