derno Posted September 5, 2007 Share Posted September 5, 2007 Hello, im new here and I just have a quick question. I'm making a 4 page form, that is HUGE (about 270 fields) and I'm using session. I was wondering if there is fast way to make all of the $_SESSION['fieldnamehere'] set to $_REQUEST['fieldnamehere'] The form works and send the info if i do this, but i dont want to type out all of the fields. Is there a faster way of doing this? I have the whole form on 1 page for the email, and i use this to grab all the fields, which works if they're all set to $_REQUEST. ob_end_flush(); ob_start(); include ('employment_form.php'); $message=ob_get_contents(); ob_end_clean(); Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/ Share on other sites More sharing options...
lemmin Posted September 5, 2007 Share Posted September 5, 2007 foreach ($_POST as $key => $value) { $_SESSION = array_flip($_SESSION); $_SESSION[] = $key; $_SESSION = array_flip($_SESSION); $_SESSION[$key] = $value; } I don't know a neater way to add the keys and values to an array other than flipping, maybe there is a better way. Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/#findComment-342331 Share on other sites More sharing options...
jvrothjr Posted September 5, 2007 Share Posted September 5, 2007 if they are truley the fieldnames you could $querystring = "Select * from ".$DB; $result=mysql_query($querystring); while(($field = mysql_fetch_field($result))) { ${"{$field->name}"} = $data22[$field->name]; } This queries the DB and sets variable name to field names. Ex: Say we had table: Users with to 2 fields First Last This loop would create two variables $First $Last Maybe could replace ${"{$field->name}"} = $data22[$field->name]; with $_SESSION["{$field->name}"] = $_REQUEST["{$field->name}"] Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/#findComment-342332 Share on other sites More sharing options...
Jessica Posted September 5, 2007 Share Posted September 5, 2007 First of all, use $_POST or $_GET, not $_REQUEST. Secondly, use a foreach(). Edit: wtf is flipping? foreach($_POST AS $key=>$value){ $_SESSION['key'] = $value; } Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/#findComment-342339 Share on other sites More sharing options...
lemmin Posted September 5, 2007 Share Posted September 5, 2007 I had no idea you can set a key by referencing it. That makes no sence to me, but I guess it works. So you could change my code to: foreach ($_POST as $key => $value) $_SESSION[$key] = $value; Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/#findComment-342353 Share on other sites More sharing options...
Jessica Posted September 5, 2007 Share Posted September 5, 2007 Which is exactly what I wrote :-P Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/#findComment-342360 Share on other sites More sharing options...
trq Posted September 5, 2007 Share Posted September 5, 2007 Which is exactly what I wrote :-P Only without the error. Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/#findComment-342451 Share on other sites More sharing options...
Jessica Posted September 5, 2007 Share Posted September 5, 2007 Ah I see it now, Thanks thorpe Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/#findComment-342453 Share on other sites More sharing options...
trq Posted September 5, 2007 Share Posted September 5, 2007 We all do it. Link to comment https://forums.phpfreaks.com/topic/68101-session-to-request/#findComment-342458 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.