Web Hosting Talk







View Full Version : Php Problem - Need Assistance


hostNOX
06-08-2002, 12:43 AM
Hello, all im currently working on our signup form the problem is i'm running into is the form is in 3 steps | step1-> step2 -> step3
The data which is in the vars is not being carried over each step so at the final and last step 3 it would dump it into an database. For some reason when i go threw the form, it executes fine its just that it only dumps in the 8 digit random character to the database, and not the other stuff from other steps. Help is greatly appreciated.

hostNOX
06-08-2002, 12:45 AM
Here is the code in an attachment.

hostNOX
06-08-2002, 12:48 AM
AHHH so very tired, does anyone know? I do know but i dont know im to tired to know but i must know if you get my condition right now :eek:

DavidU
06-08-2002, 12:52 AM
It looks to me that you aren't saving your variables across the pages.

When someone clicks to page 2 and the page2 function doesn't do anything in specific to hold the vars that it got from page1, it won't pass them to page3 and so on.

so page2 doesn't keep page1's vars and so page3 doesn't keep page2's vars -- you need to tell it to.

-davidu

hostNOX
06-08-2002, 12:55 AM
how exactly would i do that could you post an example? :eek:

Studio64
06-08-2002, 01:22 AM
example...

Page 1

<html>
<form action="page2.php">
Name: <input type="inputbox" name="Name_V"><br>
Age : <input type="inputbox" name="Age_V"><br>
<input type="submit" value="Goto Next Page">
</html>


Page 2

<html>
<form action="page3.php">
<input type="hidden" name="Name_V" value="<?echo $Name_V?>">
<input type="hidden" name="Age_V" value="<?echo $Age_V?>">

City: <input type="inputbox" name="City_V"><br>
State: <input type="inputbox" name="State_V"><br>
<input type="submit" value="Results">
</html>


Page 3

<html>
<center><B>Values To Be Entered</b><center><hr width=50>

Name : <?echo $Name_V?><br>
Age: <?echo $Age_V?><br>
City: <?echo $City_V?><br>
State: <?echo $State_V?><br>
</html>



Hope that clears up how to pass data between multiple forms.

DavidU
06-08-2002, 01:29 AM
Originally posted by Studio64
example...

Page 3

<html>
<center><B>Values To Be Entered</b><center><hr width=50>

Name : <?echo $Name_V?><br>
Age: <?echo $Age_V?><br>
City: <?echo $City_V?><br>
State: <?echo $State_V?><br>
</html>



Hope that clears up how to pass data between multiple forms.

LOL, I know how to pass data between multiple forms, I just didn't see that for some reason.

thanks, I'm still looking at your issue.

-davidu

DavidU
06-08-2002, 01:32 AM
function step2(){
global $text;

$text = "<form method='POST' action='index.php?action=step3'>
<INPUT TYPE='HIDDEN' NAME='NAME' VALUE='$_post[NAME]'>
<INPUT TYPE='HIDDEN' NAME='EMAIL' VALUE='$_post[EMAIL]'>";
}


That should probably look like:


function step2(){
global $_post, $text; //Make $_post global

$text = "<form method='POST' action='index.php?action=step3'>
<INPUT TYPE='HIDDEN' NAME='NAME' VALUE='$_post[NAME]'>
<INPUT TYPE='HIDDEN' NAME='EMAIL' VALUE='$_post[EMAIL]'>";
}


I don't think that $_post and related vars are global by default.

-davidu

benoire
06-08-2002, 08:47 AM
$_POST is an auto-global, it doesn't need globalising within a function.

The other way to do this if you don't want to define loads of hidden variables is to put the following within the form on page 2:


<?php
$varsstring = serialize($_POST);
$varsstring = rawurlencode($varsstring);
?>
<input type="hidden" name="varsstring" value="<?php echo $varsstring; ?>">


And the following on page 3:


$varsarray = unserialize(rawurldecode($_POST["varsstring"]));
$allvars = array_merge($varsarray, $_POST);
extract($allvars, EXTR_PREFIX_SAME, "var");


This will result in all POST variables from steps 1 and 2 being declared in step 3.

DavidU
06-08-2002, 10:50 AM
Originally posted by benoire
$_POST is an auto-global, it doesn't need globalising within a function.

The other way to do this if you don't want to define loads of hidden variables is to put the following within the form on page 2:


<?php
$varsstring = serialize($_POST);
$varsstring = rawurlencode($varsstring);
?>
<input type="hidden" name="varsstring" value="<?php echo $varsstring; ?>">


And the following on page 3:


$varsarray = unserialize(rawurldecode($_POST["varsstring"]));
$allvars = array_merge($varsarray, $_POST);
extract($allvars, EXTR_PREFIX_SAME, "var");


This will result in all POST variables from steps 1 and 2 being declared in step 3.

Ahh, using serialize is a great technique to eliminate the need to re-write all your old var names.

Good one Benoire!

-davidu