Page 3 of 6

Posted: Wed Jul 16, 2003 3:28 am
by Marco van Wijngaarden
as example, as you explained, i could still set up my ---step2.php--- like this (even with PHP 4.0.6):

Code: Select all

<form name="data" method="post" action="step3.php"> 
<?php 
session_start(); 

$klantgegevens = array( 
"bedrijf"     =>    $bedrijf, 
"naam"        =>    $naam, 
); 
?>
<P>regel1<input type="text" name="regel1"></P> 
<P>regel2<input type="text" name="regel2"></P> 

<input type="submit" name="Submit" value="To step 3"> 
</FORM>
but when i want to print a single value from an array such as above $klantgegevens, how should i write my code? I understand that this won't work in my version:

Code: Select all

print ("{$_SESSION[klantgegevens][bedrijf]}<BR>\n");

also.... if i want to fill a hidden field, how will i get this to work:

Code: Select all

&lt;?php 
session_start(); 
?&gt;
&lt;input type="hidden" name="bedrijf" value="&lt;?php echo $_POST&#1111;'klantgegevens']&#1111;'bedrijf']?&gt;"&gt;
NOTE: that should be [questionmark][greater then]

for your information, this last hiddenfield will be needed for a "liveconnect" to a flash file (sending variables to flash)

Posted: Wed Jul 16, 2003 4:05 am
by Heavy
Dont reply right away. Read all the links I have provided before. Then apply your newfound knowledge to your scripts.
Marco van Wijngaarden wrote:

Code: Select all

<form name="data" method="post" action="step3.php"> 
<?php 
session_start(); 

$klantgegevens = array( 
"bedrijf"     =>    $bedrijf, 
"naam"        =>    $naam, 
); 
?>
<P>regel1<input type="text" name="regel1"></P> 
<P>regel2<input type="text" name="regel2"></P> 

<input type="submit" name="Submit" value="To step 3"> 
</FORM>
I have mentioned you must start the session before any output. Why don't you?
Marco van Wijngaarden wrote: but when i want to print a single value from an array such as above $klantgegevens, how should i write my code? I understand that this won't work in my version:

Code: Select all

print ("{$_SESSION[klantgegevens][bedrijf]}<BR>\n");

also.... if i want to fill a hidden field, how will i get this to work:

Code: Select all

&lt;?php 
session_start(); 
?&gt;
&lt;input type="hidden" name="bedrijf" value="&lt;?php echo $_POST&#1111;'klantgegevens']&#1111;'bedrijf']?&gt;"&gt;
NOTE: that should be [questionmark][greater then]

for your information, this last hiddenfield will be needed for a "liveconnect" to a flash file (sending variables to flash)
It is OK to fill in the hidden field like that, just be sure to start the <form> first so it surrounds the hidden field.

There are tree reasons to why the above does not work:
1 you didn't start the session before output.
2 the $_SESSION array doesn't exist in your version of PHP
3 the $_POST array doesn't exist in your version of PHP

Checklist:
* In version 4.0.6 the $_SESSION and $_POST didn't exist. Instead there were $HTTP_SESSION VARS and $HTTP_POST VARS. If register globals is on, you don't have to use them. Still I encourage you to do things without register_globals. Check the ONLINE manual why, because the online manual has comments that might help in certain situations.

* start session before any output.

* when you do

Code: Select all

<?php 
print("Variable from an array {$arr['textindex']}");
?>
it shouldn't be

Code: Select all

<?php 
print("Variable from an array {$arr[textindex]}");
?>
If you still dont get it, read again SLOWLY. Don't skim! programmers must not skim! you need to discover every little ' or . or , or ;

Posted: Wed Jul 16, 2003 4:07 am
by Heavy
Hey!
I like you!
You make my post score grow! :lol:

Posted: Wed Jul 16, 2003 4:30 am
by Marco van Wijngaarden
:D i'm glad to be working on your post score!

anyway... you posted your reply while i was writing my last one, so that's why... anyway... i'm reading right now, so don't worry!
One thing though... i don't really understand what you meant by
I have mentioned you must start the session before any output. Why don't you?
I did start with session_start();
so what am i doing wrong??

Posted: Wed Jul 16, 2003 5:26 am
by redhair
This is a eehh...interesting post :lol:
Keep up the good work!
(And read!)

Posted: Wed Jul 16, 2003 5:32 am
by Heavy
Marco van Wijngaarden wrote:One thing though... i don't really understand what you meant by
I have mentioned you must start the session before any output. Why don't you?
I did start with session_start();
so what am i doing wrong??
Hmmm.... Please read this again:
viewtopic.php?p=50188#50188
Focus on the two given versions of "step2.php"
and this:
viewtopic.php?p=50195#50195
and this:
http://se2.php.net/session_start important!

Now. How are you? :wink:

Posted: Wed Jul 16, 2003 8:16 am
by m3rajk
marco-

http://people.brandeis.edu/~m3rajk/JMT/ ... signup.txt

i have it all in one page, i'm also using a new version, but i use cookies (which sessions sometimes use)the other thing it uses is hidden fields.. but depending on what's there, you could do something like me and insert into the db after certain steps

Posted: Wed Jul 16, 2003 8:18 am
by Marco van Wijngaarden
well folks... i'm about to give up here.... to me it seems that php.net has most documentation writen for 4.2.x or higher....

Unless someone comes up with some helpfull hints on getting session to work with PHP 4.0.6 but i don't seem to succeed in it!

ohh and what m3rajk just posted... that goes way beyond my knowledge of PHP so... I don't know anything about databases so that would get me starting a new subject on here in order to gain some more post-counts for you guys! thanks anyway!

:cry: :cry: :cry:

Posted: Wed Jul 16, 2003 8:37 am
by redhair
....in order to gain some more post-counts for you guys!
They are all trying to help you Marco....it has nothing to do with 'scores'.
I suggest strongly you get a book (or a few) about php. Especially when you are a beginner. It will make life so much more easier for you ;-)

Posted: Wed Jul 16, 2003 8:45 am
by m3rajk
lol. marco, i'm on your level. thing is i know the theory behind all this so i can conceptualize it. do you have a messenger? if i have a better idea of what you're doing i can be of much more help

Posted: Wed Jul 16, 2003 8:49 am
by twigletmac
Marco van Wijngaarden wrote:well folks... i'm about to give up here.... to me it seems that php.net has most documentation writen for 4.2.x or higher....
Because that's the version that most people are using - 4.0.x is very outdated now. FWIW, sessions on 4.0.6 were a real nightmare (at least I think they're ten times easier in newer versions). Have you looked at the session functions in the manual - most importantly session_register() and session_is_registered().

Check out this tutorial by Jason that will work with your PHP version:
Sessions for Newbies

Mac

Posted: Wed Jul 16, 2003 8:56 am
by Marco van Wijngaarden
ohh... :D i'm just joking about scores for posts... refering to an earlier post!

Anyway, i have a book "PHP for the world wide web" which i found very usefull! I do agree that such documentation is a must for each newbie and probably more experienced programmer as well!

But in specific situations such as mine... which is dealing with a provider with an out-dated php version (4.0.6)... that won't be that helpfull i guess!?

The trouble i have is php.net has most documentation writen for 4.0.2 or above, and that puts me into more trouble... as i am still learning to understand PHP... the next thing i have to do is finding out how to get it to work on earlier versions... that drives me up the wall cos i can't find my answers!

well... time for some relaxing now... :(

But i am very happy about all your help folks! I greatly appreciate it!

Posted: Wed Jul 16, 2003 9:01 am
by m3rajk
marco: before you give up.. is this personal? if yso don't bother with 4.0.6 most places have at least 4.1.0


if this is work, then talk to your it dept about getting 4.3 or higher


when learning a lnguage you should try to learn a near-new nversion. something that evolves as fast as php you want to start one step back because most help you can get will be people that are updating their own knowledgebase to keep current

Posted: Wed Jul 16, 2003 9:34 am
by Heavy
I just could not keep my hands off of it.
And I had to test what I have been talking about so much, to see that I am not lying to you.

So here it is, and it works without register globals on.
Do it yourself next time.

I know you already know that the question-mark-greater-than doesn't show, so don't post about that. :roll:

Good luck in learning.

Be sure to put the '<?php' as the absolutely first characters of the file, otherwise the session won't start.

step1.php:

Code: Select all

<form name="klantgegevens" method="post" action="step2.php">
<P>Bedrijf <input type="text" name="bedrijf" size="50"></P>
<P>Naam <input type="text" name="naam" size="50"></P>
<P><input type="submit" name="Submit" value="To step 2">
</form>
step2.php:

Code: Select all

<?php
session_start();
session_register('klantgegevens');
$Klantgegevens = array( "bedrijf" => $HTTP_POST_VARS['bedrijf'],"naam" => $HTTP_POST_VARS['naam']);
		
$HTTP_SESSION_VARS['klantgegevens'] = $Klantgegevens;
		
echo "<pre>";
print_r ($HTTP_SESSION_VARS['klantgegevens']);
echo "</pre>";
?>
<form name="data" method="post" action="step3.php">
<P>regel1<input type="text" name="regel1"></P>
<P>regel2<input type="text" name="regel2"></P>
<input type="submit" name="Submit" value="To step 3">
</FORM>
step3.php:

Code: Select all

<?php
session_start();
session_register('data');
$Data = array( "regel1"=>$HTTP_POST_VARS['regel1'],"regel2"=>$HTTP_POST_VARS['regel2']); 

$HTTP_SESSION_VARS['data'] = $Data;

echo "<pre>";
print_r ($HTTP_SESSION_VARS);
echo "</pre>";
?>
<form name="check" method="post" action="step4.php">
<p><input type="submit" name="Submit" value="To step 4"></p>
</form>
step4.php:

Code: Select all

<?php
session_start();
echo "<pre>";
print_r ($HTTP_SESSION_VARS);
echo "</pre>";
?>

Posted: Wed Jul 16, 2003 10:21 am
by Marco van Wijngaarden
m3rajk the server i am using is actually a host... it's Planet Internet here in Holland and i mentioned this to them... i really am surprised by the fact that such a well known provider has such out-dated stuff running!

Heavy gee, thanks! 8O i'll see if this will work for me! but i also got another idea to go around this trouble (cos what if my host WILL decide to upgrade after reading my complaining for instance?) The idea i have is to use cookies... that's also new for me, but what do you think?