amitchugh Posted December 13, 2011 Share Posted December 13, 2011 hello masters i have download a template . when i run it on my pc using wamp, it shows errors. as i do not know much about php ( i m learning it), please help me to correct the mistakes. thanks. here is a screenshot of errors page. Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/ Share on other sites More sharing options...
amitchugh Posted December 13, 2011 Author Share Posted December 13, 2011 zoomed verson of screenshot http://postimage.org/image/59c5tjgrt/ Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297505 Share on other sites More sharing options...
scootstah Posted December 13, 2011 Share Posted December 13, 2011 Code would be nice. Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297512 Share on other sites More sharing options...
amitchugh Posted December 13, 2011 Author Share Posted December 13, 2011 screenshot is full of errors, i think so. And you say code is nice. How can you say that ? Can you tell me where should be the error. Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297517 Share on other sites More sharing options...
scootstah Posted December 13, 2011 Share Posted December 13, 2011 Did you even read the errors? Undefined variable: _SESSION In C:\wamp\www\includes.php on line 2. This tells you that the error is on includes.php on line 2. Rinse and repeat. Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297520 Share on other sites More sharing options...
amitchugh Posted December 13, 2011 Author Share Posted December 13, 2011 this is firt 2 lines in includes.php <?php $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE username='".$_SESSION['username']."'")); i do no get it. do you know what is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297521 Share on other sites More sharing options...
scootstah Posted December 13, 2011 Share Posted December 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297525 Share on other sites More sharing options...
amitchugh Posted December 13, 2011 Author Share Posted December 13, 2011 thanks a lot. but i do not understand it. i start learning php just a month ago. but if you have some time plz guide, how to fix it. Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297532 Share on other sites More sharing options...
Drummin Posted December 13, 2011 Share Posted December 13, 2011 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']."'")); Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297536 Share on other sites More sharing options...
amitchugh Posted December 13, 2011 Author Share Posted December 13, 2011 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(); Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297538 Share on other sites More sharing options...
scootstah Posted December 13, 2011 Share Posted December 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297541 Share on other sites More sharing options...
amitchugh Posted December 13, 2011 Author Share Posted December 13, 2011 so what you need to fix it Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297544 Share on other sites More sharing options...
Drummin Posted December 14, 2011 Share Posted December 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297757 Share on other sites More sharing options...
amitchugh Posted December 14, 2011 Author Share Posted December 14, 2011 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/253090-user-login-template-error/#findComment-1297785 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.