Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2012, 06:28 PM   PM User | #1
Philosophaie
New Coder

 
Join Date: Sep 2010
Posts: 46
Thanks: 1
Thanked 1 Time in 1 Post
Philosophaie is an unknown quantity at this point
Methods of transferring data from PHP to HTML.

I have brought data into PHP using the "POST" method:

Code:
$data = filter_input(INPUT_POST, "data");
I have a header that redirects the site back to the same site without the data.

I would like to know some methods on how to transfer $data back to HTML after executing a header so I can place the data back into the textboxes.
Philosophaie is offline   Reply With Quote
Old 02-25-2012, 07:01 PM   PM User | #2
chose
New Coder

 
Join Date: Feb 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
chose is an unknown quantity at this point
if you want to keep data in inputs e.g after refresh
you can use session

PHP Code:
....
$_SESSION $_POST;
....

echo 
"<input type="text" name="somefield" value=" $_SESSION['somefield'] . "/>"

Last edited by chose; 02-25-2012 at 07:09 PM..
chose is offline   Reply With Quote
Old 02-25-2012, 07:47 PM   PM User | #3
Philosophaie
New Coder

 
Join Date: Sep 2010
Posts: 46
Thanks: 1
Thanked 1 Time in 1 Post
Philosophaie is an unknown quantity at this point
This is what I wrote in my PHP file it gave me an error in the "echo".

From what I gather this will reinsert the data that was originally in the html website into the new website created by the "header".

What am I doing wrong here?

Code:
        session_start();
    	$mo=filter_input(INPUT_POST, "mo");
        $_SESSION=$mo;
        echo "<input type="text" name="mo" value=" . $_SESSION['mo'] . "/>";  
        session_write_close();

Last edited by Philosophaie; 02-25-2012 at 08:05 PM..
Philosophaie is offline   Reply With Quote
Old 02-25-2012, 08:07 PM   PM User | #4
chose
New Coder

 
Join Date: Feb 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
chose is an unknown quantity at this point
you get value of 'mo' field in post array in that line
PHP Code:
$mo=filter_input(INPUT_POST"mo"); 
if you need just a mo value, you can do something like this
PHP Code:
        session_start();
        
$mo=filter_input(INPUT_POST"mo");
        
$_SESSION['mo']=$mo;
        echo 
"<input type="text" name="mo" value=" $_SESSION['mo'] . "/>";  
        
session_write_close(); 
chose is offline   Reply With Quote
Old 02-25-2012, 08:33 PM   PM User | #5
Philosophaie
New Coder

 
Join Date: Sep 2010
Posts: 46
Thanks: 1
Thanked 1 Time in 1 Post
Philosophaie is an unknown quantity at this point
I keep getting an error on the "echo". I typed the same as what was in the htm file except adding the session:

Code:
echo "<input type="text" name="mo" value=" . $_SESSION['mo'] . " size="4"/>";
It keeps giving me an error:

Quote:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'
I checked all the ";" are at the end of all the lines except "{" and "}" also all the quote marks are accounted for.
Philosophaie is offline   Reply With Quote
Old 02-25-2012, 08:40 PM   PM User | #6
chose
New Coder

 
Join Date: Feb 2012
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
chose is an unknown quantity at this point
oh,

PHP Code:
echo "<input type=\"text\" name=\"mo\" value=\"" $_SESSION['mo'] . "\" size=\"4\"/>"
chose is offline   Reply With Quote
Old 02-25-2012, 08:42 PM   PM User | #7
litebearer
Regular Coder

 
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
litebearer is on a distinguished road
haven't read whole thread but this
Code:
echo "<input type="text" name="mo" value=" . $_SESSION['mo'] . " size="4"/>";
is closing quotes BEFORE you really intend. you can...
1. escape quotes or
2. drop in and out of php
Code:
 ?>
   <input type="text" name="mo" value="<?PHP echo $_SESSION['mo']; ?>" size="4"/><?PHP
litebearer is offline   Reply With Quote
Old 02-26-2012, 09:23 AM   PM User | #8
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,880
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
Quote:
Originally Posted by litebearer View Post
is closing quotes BEFORE you really intend. you can...
1. escape quotes or
2. drop in and out of php
Code:
 ?>
   <input type="text" name="mo" value="<?PHP echo $_SESSION['mo']; ?>" size="4"/><?PHP
3. use single quotes to denote the string (you need to step out of the string to add variables)
4. use HERDOC syntax to denote the string
5. format your string using one of the printf() functions
6. use single quotes to enclose the HTML attribute values
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 02-26-2012, 07:07 PM   PM User | #9
Philosophaie
New Coder

 
Join Date: Sep 2010
Posts: 46
Thanks: 1
Thanked 1 Time in 1 Post
Philosophaie is an unknown quantity at this point
In html I wrote:

<input type="text" name="mo" value="<?PHP echo $_SESSION['mo']; ?>" size="4"/>

All it prints out in the textbox is:

<?PHP echo $_SESSION['mo']; ?>

And nothing else because it is in parentheses! I tried without, with ' ' and " ". Is there no other way?

Last edited by Philosophaie; 02-26-2012 at 07:11 PM..
Philosophaie is offline   Reply With Quote
Old 02-26-2012, 08:36 PM   PM User | #10
litebearer
Regular Coder

 
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
litebearer is on a distinguished road
is the file that you are displaying an .html or a .php?
Quote:
In html I wrote:

<input type="text" name="mo" value="<?PHP echo $_SESSION['mo']; ?>" size="4"/>

All it prints out in the textbox is:

<?PHP echo $_SESSION['mo']; ?>

And nothing else because it is in parentheses! I tried without, with ' ' and " ". Is there no other way?
litebearer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 03:18 AM.


Advertisement
Log in to turn off these ads.