Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-16-2008, 09:19 PM $_SESSION Help
Skilled Talker

Posts: 64
Name: Ralph Freshour
Trades: 0
I'm trying to load user data from my index.php page using a text box and a submit button.
My main php page is index.php and I have a post call to an index_dispatcher.php script that opens the database and loads some data into some $_SESSION variables regarding the user name typed into the text box. My debug prints show the DB is opening fine and the data is being loaded into the $_SESSION vars fine too.
Then my index_dispatcher.php calls my index.php file again but the $_SESSION vars are not set in index.php.
If I repeat this process, meaning if I type in the user name into the text box again and click on the submit button again, then it will work.
Does anyone know why it takes two times for the $_SESSION variables (which get set in index_dispatcher.php) to get set in the index.php file?
I should also add that this behavior is with Firefox and Safari browsers - IE 7.0 works the first time but FF/Safari needs this to happen twice!
index.php
PHP Code:
<FORM NAME="index_form.php" ACTION="index_dispatcher.php" METHOD="post"
index.php text box and submit code
PHP Code:
Name <INPUT TYPE="text" NAME="frm_name"> <INPUT TYPE="submit" NAME="frm_login_name" VALUE="Login"
index_dispatcher.php code:
PHP Code:
$php_string strtolower($_POST["frm_login_name"]); 
// open mysql database connection -------------------------------- 
//                           server      username       password 
$php_linkID mysql_connect("localhost","db16_ralph","atg568h93hf65jn8"); 
if (
$php_linkID != TRUE
   { 
     print 
'<br>database connection failed.<br>'
     exit; 
   } 
// select the main database -------------------------------------- 
$php_resultID mysql_select_db("db_db",$php_linkID); 
if (
$php_resultID != TRUE
   { 
     print 
"database selection failed.<br>"
     exit; 
   } 
$php_SQL "SELECT * FROM Salesmen WHERE login_name = '".$php_string."'"
$php_resultID mysql_query($php_SQL$php_linkID); 
$php_row mysql_fetch_object($php_resultID); 
$php_row_count mysql_num_rows($php_resultID); 
if (
$php_row_count 0
   { 
     
$_SESSION['php_g_sc_login_name'] = $php_row->login_name
     
$_SESSION['php_g_sc_first_name'] = $php_row->first_name
      
$_SESSION['php_g_sc_last_name'] = $php_row->last_name
print 
$_SESSION['php_g_sc_first_name'].'<br>'
print 
$_SESSION['php_g_sc_last_name'].'<br>'
   } 
__________________
RalphF
Business Text Messaging Services

Please login or register to view this content. Registration is FREE
rfresh is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-16-2008, 09:24 PM Re: $_SESSION Help
PeachyJuice's Avatar
Super Talker

Posts: 116
Name: Michele T.
Location: Ny, Ny
Trades: 1
You need to start the session on both pages. Without that, the server doesn't know it's setting up a connection, so the $_SESSION variables won't do you much good. Add session_start(); to the VERY beginning of your pages. Nothing can come before this, otherwise you'll get errors.

P.s. you should probably remove your db username/password from your script xD
__________________
Freelance web+graphic designer and PHP developer.

Please login or register to view this content. Registration is FREE
PeachyJuice is offline
Reply With Quote
View Public Profile
 
Old 06-16-2008, 09:26 PM Re: $_SESSION Help
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Can we see your full code?
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 06-17-2008, 02:21 PM Re: $_SESSION Help - Resolved
Skilled Talker

Posts: 64
Name: Ralph Freshour
Trades: 0
I added a header() statement to the top of my index_dispatcher.php file and that did the trick.

PHP Code:
<?php
session_start
();
header ("location: index.php");
?>
Thanks to everyone who responded.
__________________
RalphF
Business Text Messaging Services

Please login or register to view this content. Registration is FREE
rfresh is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to $_SESSION Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16519 seconds with 12 queries