Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    1
    Thanked 1 Time in 1 Post

    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.

  • #2
    New Coder
    Join Date
    Feb 2012
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    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 08:09 PM.

  • #3
    New Coder
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    1
    Thanked 1 Time in 1 Post
    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 09:05 PM.

  • #4
    New Coder
    Join Date
    Feb 2012
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    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(); 

  • #5
    New Coder
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    1
    Thanked 1 Time in 1 Post
    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:

    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.

  • #6
    New Coder
    Join Date
    Feb 2012
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    oh,

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

  • #7
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    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

  • #8
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,469
    Thanks
    13
    Thanked 361 Times in 357 Posts
    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
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #9
    New Coder
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    1
    Thanked 1 Time in 1 Post
    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 08:11 PM.

  • #10
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •