Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2012, 10:56 AM   PM User | #16
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
updates.php should look something like this to prevent the undefined index error after login:
PHP Code:
<?php
session_start
();
include 
'config.php';

if(isset(
$_POST['user']) && isset($_POST['pass']))
{
    
$user mysql_real_escape_string($_POST['user']);
    
$pass mysql_real_escape_string($_POST['pass']); 
    
$stat mysql_fetch_array(mysql_query("select * from members where user='$user' and pass='$pass'"));

    
$_SESSION['stat'] = $stat;

    print 
"Welcome {$stat['user']}";
}
else if(isset(
$_SESSION['stat']['user']))
{
    print 
"Welcome {$_SESSION['stat']['user']}";
}
Inigoesdr is offline   Reply With Quote
Old 10-04-2012, 07:25 PM   PM User | #17
Feerick11
New Coder

 
Join Date: Sep 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Feerick11 is an unknown quantity at this point
It been a while since I checked this post as ive been very busy .Ive just made the relevant changes to updates.php and its now just giving me a blank page. I really want to get this sorted
Feerick11 is offline   Reply With Quote
Old 10-04-2012, 08:28 PM   PM User | #18
Feerick11
New Coder

 
Join Date: Sep 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Feerick11 is an unknown quantity at this point
Obviously the session still isnt carrying over. Its frustrating because I want to continue with this site im just well and truly stuck here.
Feerick11 is offline   Reply With Quote
Old 10-04-2012, 09:56 PM   PM User | #19
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
How do you know the session isn't being carried over? - Did you not read my comment previously about you not even using the $_SESSION array? - That is where you store things. In your next script you then call session_start() and the $_SESSION array then contains all the keys and values you used previously in your last script.

I've not seen you use $_SESSION anywhere so how can you claim it's not working? - Anything you want made available to the next script must be put into the session array like this:

Script one
PHP Code:
session_start();
$_SESSION['text'] = 'Hello'
Script two
PHP Code:
session_start();
print 
$_SESSION['text']; 
As for your blank page, if you're on wamp then you'll have an apache error log somewhere which will list the error with the page.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.

Last edited by tangoforce; 10-04-2012 at 09:59 PM..
tangoforce is offline   Reply With Quote
Old 10-05-2012, 11:32 AM   PM User | #20
Feerick11
New Coder

 
Join Date: Sep 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Feerick11 is an unknown quantity at this point
Let me see if I understand what you mean. In the past I would have just put the following in my header file.

$stat = mysql_fetch_array(mysql_query("select * from members where user='$user' and pass='$pass'"));

The session would of kept that alive and then when I wanted to show someones user name I would of just put $stat[user]. But now I have to use session variables. Is that correct?
Feerick11 is offline   Reply With Quote
Old 10-05-2012, 12:41 PM   PM User | #21
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Feerick11 View Post
The session would of kept that alive
No it wouldn't. $stat would be forgotten as soon as the script ended.

To use a session, anything you want remembered between scripts must be put into the $_SESSION array. I've made this clear more than once to you yet you seem to do anything but accept it.

Quote:
Originally Posted by Feerick11 View Post
But now I have to use session variables. Is that correct?
No it's not correct. You've ALWAYS had to use session variables it's just that you have not been doing so. If you go back and read my previous replies you will see I have been telling you this multiple times.

Normal variables that you use (eg $User or $stat) were never remembered by sessions. They were available in other files that you might include() or require() but not between scripts on different urls and http calls.

Anything you want remembered between two scripts that are at different urls must go into the $_SESSION array. I've given you a basic code sample above so please use it! It isn't hard, just a call to session_start() in your script and then use the $_SESSION array just like any other array. It's really easy to do
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:46 AM.


Advertisement
Log in to turn off these ads.