简体   繁体   中英

php code logic for transferring data from one page to another

i made a (php) form, and used php session and post to transfer the form data to another page, which gives the user an option to have a look at the data and if wrong he shall move to the main form..

now here is what i did

on page1 i made a main form say form1, when user clicks on submit, i saved the data to DB and added that id to a session, and sent that session to next page using the same id on next page i called from db matching the same id and displayed data accordingly..

now i displayed the data (on the second page) inside a div styled with css, the logic for this second page is giving the user the choice if the data is wrong he can edit, and bottom of this div i added a button with code

<a href="#" class="button3">Edit</a> 

now my question is this, what shall be next? my target is, if user clicks on this edit button he shall be taken to main form (ie page1, form1) and there he shall has the option of editing the data in the same id. How can i achieve this friends?

Also i used

<?php session_start(); ?> 

on top of both the pages...

Just change your code on the form1 page to; load the data from the database if the id of the record is set in your session variable.

Then if the user decides the data is wrong he just gets sent back to form1 and has the possibility to make changes.

Use something similar to: value="<?php echo $data['name']" in your input fields.

Then check for the id and load the data:

if(isset($_SESSION['record_id'])) {
    // Do a query with `where id = record_id
    // Fetch the data in the $data variable
}

IF you dont want use GET then use SESSION.

in file.php set

     $_SESSION['your_id'] = $theid ;

and in your edit.php retrieve it like that

   $id = $_SESSION['your_id']  ;

of course you must session_start in both files.

If you already have all the data in your session you can simply link back to the first page. All you have to do is set all of your fields on the first page to pre-fill with the session data as long as it isset . This way, when you go back the forms will auto fill with the data the user has already entered and they can simply change what is needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM