...

View Full Version : Methods of transferring data from PHP to HTML.



Philosophaie
02-25-2012, 07:28 PM
I have brought data into PHP using the "POST" method:


$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.

chose
02-25-2012, 08:01 PM
if you want to keep data in inputs e.g after refresh
you can use session



....
$_SESSION = $_POST;
....

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

Philosophaie
02-25-2012, 08:47 PM
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?


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

chose
02-25-2012, 09:07 PM
you get value of 'mo' field in post array in that line
$mo=filter_input(INPUT_POST, "mo");

if you need just a mo value, you can do something like this


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

Philosophaie
02-25-2012, 09:33 PM
I keep getting an error on the "echo". I typed the same as what was in the htm file except adding the session:


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

It keeps giving me an error:


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.

chose
02-25-2012, 09:40 PM
oh,


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

litebearer
02-25-2012, 09:42 PM
haven't read whole thread but this

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

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

Dormilich
02-26-2012, 10:23 AM
is closing quotes BEFORE you really intend. you can...
1. escape quotes or
2. drop in and out of php

?>
<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

Philosophaie
02-26-2012, 08:07 PM
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
02-26-2012, 09:36 PM
is the file that you are displaying an .html or a .php?

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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum