homepage Welcome to WebmasterWorld Guest from 54.237.71.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
session problem
session_register and if
psybox




msg:1295254
 12:41 pm on Nov 1, 2002 (gmt 0)

I have the following code -

if ($personal_1 == "y"); {
$personal="$personal_1";
if ($personal_2 == "y"); {
$personal="$personal_2";
if ($personal_3 == "y"); {
$personal="$personal_3";
}
}
}
?> Next form to be filled in goes <a href="profile.php">here</a>

It looks at form1 and if radio button personal_1 is checked (equal to y) then it sets it as $personal....same for _2 etc. Elsewhere on the page I have £personal_1 (_2 etc) equal html so html is printed instead of just "y".

However when I print $personal - it always returns the html for $personal_3 as it is the last one - instead of the checked radio box html. I have tried inserting if / elseif into it - but always get errors.

I'm new to php and chuffed to get this far - but now I'm stuck!

You can see the demo at I am trying to achieve.

Any ideas please?

[edited by: psybox at 1:01 pm (utc) on Nov. 1, 2002]

 

Nick_W




msg:1295255
 12:50 pm on Nov 1, 2002 (gmt 0)

Hi, welcome to WebmasterWorld!

First idea: Drop the url ;) We try not to post personal url's...

Secondly, you need to rewrite your code a little:

[pre]
if ($personal_1 == "y") {
$personal="$personal_1";
}
if ($personal_2 == "y") {
$personal="$personal_2";
}
if ($personal_3 == "y") {
$personal="$personal_3";
}

?> Next form to be filled in goes <a href="profile.php">here</ a>
[/pre]

Notice I dropped the ; after in the if line?

Other than that, it sounds like a problem with your html. That all the radio buttons are being checked or something. Why not post that and we'll take a look ;)

Nick

[edited by: jatar_k at 4:51 pm (utc) on Nov. 1, 2002]
[edit reason] fixed code tag [/edit]

psybox




msg:1295256
 1:11 pm on Nov 1, 2002 (gmt 0)

Hi Nick - that was fast reply! The only thing about the html page is that the value of each button is equal to "y". Here is the entire page - which includes the start session..

<?php

session_start(); // start the session

session_register('personal');

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Personal details</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>

</HEAD>
<BODY>
<P><B>Personal Details </B><BR>Here are three options. Which of these options
would you choose for Sarah? <BR>Before choosing, look at the advice</P>
<CENTER>
</CENTER>
<p>Choose an option for Sarah by clicking its <B>Select</B> button. Then click
the <B>Confirm</B> button at the bottom. </p>
<form name="personal" method="post" action="education.php">
<table border=0 width=600 valign="top" align="center">
<tbody>
<tr>
<td colspan=3 valign=top width=600>
<h4 align=center>This is option 1</h4>
<p>
<center>
<b><font face=arial size=1>Sarah <br >
<br Street Any 12>
Anytown <br>
Anywhere AN1 1NA </font></b>
</center>
<p></p>
<p></p>
</td>
<tr>
<td width=200 valigh="top"><font face="arial" size="1">Telephone:<br>
<br>
e-mail <br>
Nl number </font>
<p></p>
</td>
WE 12 34 56A
<td width=200 valigh="top">
<p>
<center>
<font face=arial size=1>(H) 0191 123 4567<br>
(M) 0771 111 1111 <br>
</font><font color=#0000ff face=arial
size=1><b>sa.rah@NTLworld.com<br>
</b></font><b><font face=arial size=1>WE 12 34 56A </font></b>
</center>
<p></p>
</td>
<td align=right width=200 valigh="top"><font face="arial" size="1">d.o.b.
7/1/80 <br>
British <br>
Single <br>
Good health </font>
<p></p>
</td>
</tr>
</tbody>
</table>
<p align="center">
<input type="radio" name="personal_1" value="y">
Select Option 1</p>
<p>&nbsp;</p>
<table align="center">
<tbody>
<tr>
<td valign=top width=375>
<h4 align=center>This is option 2</h4>
<p>
<center>
<font face=arial size=2><b>SARAH </b></font>
</center>
<p></p>
<p>
<center>
<font face="arial" size="1">12 Any Street, Anytown, Anywhere, ANI INA
</font>
<p></p>
<p><font face=arial size=1>Tel: 0191 123 4567 &nbsp; &nbsp; &nbsp; E-mail:</font><font
color=#0000ff face=arial size=1><b> sa.rah@NTLworld.com</b></font> <font
face=arial size=1>&nbsp; &nbsp; &nbsp; d.o.b. 7/1/80 </font></p>
</center>
</td>
<td valign=top width=375>
<h4 align=center>This is option 3</h4>
<p>
<center>
<font face="arial" size="2"><b>SARAH </b></font>
<p></p>
<p><b><font face=arial size=2></font></b><b><font face=arial size=1>12
Any Street <br>
Anytown <br>
Anywhere AN1 1NA </font></b></p>
<p> <b><font face=arial size=1>0191123 4567 &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; </font><font color=#0000ff face=arial size=1>sa.rah@NTLworld.com
</font></b></p>
</center>
</td>
</tr>
<tr>
<td valign=top width=375>
<div align="center">
<input type="radio" name="personal_2" value="y">
Select Option 2</div>
</td>
<td valign=top width=375>
<p>
<center>
</center>
<p align="center">
<input type="radio" name="personal_3" value="y">
Select Option 3</p>
</td>
</tr>
</tbody>
</table>
<p align="center">
<input type="submit" name="Submit" value="Continue">
</p>
</form>
<CENTER>
</CENTER>
<P></P>
<CENTER></CENTER>
<P></P></BODY></HTML>

Nick_W




msg:1295257
 1:29 pm on Nov 1, 2002 (gmt 0)

Bit difficult to sift through all those font tags sahra!

If it still doesn't work after changing your php then let's just see the form ;) ... I take it you are starting a session on education.php right?

Nick

psybox




msg:1295258
 1:37 pm on Nov 1, 2002 (gmt 0)

edited!

Okay - I've simplified everything. On profile.php when I print $personal - nothing gets printed now!

page 1 - personal.htm goes to education.php which goes to profile.php. Code below.

PERSONAL.HTM

<?php

session_start(); // start the session

session_register('personal');

?>
<body>
<form name="personal" method="post" action="education.php">
<p>This is option 1</p>
<p>
<input type="radio" name="personal_1" value="y">
Select Option 1 </p>
<p>This is option 2</p>
<p>
<input type="radio" name="personal_2" value="y">
Select Option 2</p>
<p>This is option 3</p>
<p>
<input type="radio" name="personal_3" value="y">
Select Option 3</p>
<p>
<input type="submit" name="Submit" value="Continue">
</p>
</form>
</BODY></HTML>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EDUCTAION.PHP

<?php

session_start();

session_register('personal');
$personal_1 = 'This is option 1 - html hopefully in tables';
$personal_2 = 'This is option 2 - - html hopefully in tables';
$personal_3 = 'This is option 3 - - html hopefully in tables';

if ($personal_1 == "y") {
$personal="$personal_1"; }
if ($personal_2 == "y") {
$personal="$personal_2"; }
if ($personal_3 == "y") {
$personal="$personal_3"; }

?> Next form to be filled in goes <a href="profile.php">here</a>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
PROFILE.PHP

<?php
session_start(); // start the session
session_register('personal');

?>
<html>
Here is what you chose
<?php
print("$personal");
?>

</html>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved