简体   繁体   中英

how to pass the input value from one php page to another php page

I have to store some input values in a database(mysql).
Like firstname, lastname, phone no, mobile no etc.

Using select query i can fetch all the records from the database and show in one webpage.
In a webpage using mouse click on one set of record and (with help of href link) it open another webpage and show selected(click) record set.

You can use the $_GET function across URLs. Otherwise you could create a session or a cookie and store the information about a user.

$_GET uses data from the URL. You define this first by using a question mark and then the variable name followed by an equals sign and then the value. You can add multiple variables separated by 'and' symbols. You can use this to transfer data across pages. For example, you could create a list of the variables that need to be linked to and then create a URL structure:

$firstname = "Jane";
$lastname = "Doe";
$phone = "0123456789";
$mobile = "9876543210";
$URL = "secondpage.php?firstname=".$firstname."&lastname=".$lastname."&phone=".$phone."&mobile=".$mobile;

This would mean, under these circumstances, that $URL would echo as "secondpage.php?firstname=Jane&lastname=Doe&phone=0123456789&mobile=9876543210". You could link to this URL and then on secondpage.php you could GET the variables as follows:

$firstname = $_GET['firstname'];
$lastname = $_GET['lastname'];
$phone = $_GET['phone'];
$mobile = $_GET['mobile'];

However, some people may consider this to be messy or you may not wish for your users to be able to edit the values. If they edit the URL, they might be able to change how the page functions or inject malicious code. To solve this you can use the $_SESSION function instead, this data is stored on the server and cannot be changed.

To do this you need to begin the session with the following function on both pages:

session_start();

You can then define variables on the first page like this:

$_SESSION['firstname'] = "Jane";
$_SESSION['lastname'] = "Doe";
$_SESSION['phone'] = "0123456789";
$_SESSION['mobile'] = "9876543210";

and then you are able to call these variables across the site. The only problem with this is that the session could run out and may need to be redefined. You can use the public variables in the same way you would use any others, the only difference being is that they are global to the server.

echo "Welcome back, ".$_SESSION['firstname']."!"; //echos as "Welcome back Jane!"

You can use built-in arrays like $_SESSION or $_GET or $_REQUEST

Take a look

use normal form elements first page

<form action="page2.php" method="post">
     <input type="text" name="name" value="">
     <input type="password" name="password" value="">
     <input type="submit" value="save"> 
</form>

in page2.php

echo $_POST['name'];
echo $_POST['password'];

this way u can pass value from one page to another

使用$ _GET,但如果要根据用户在许多页面中使用同一内容,请使用$ _SESSION

So what you are trying to say is,

  1. You want a Master Set Page; that will list all the records of Person(I suppose)
  2. Then you need a link on the Master Page; something like 'View details' that will link up to another page, considerably its Detail Set which will show details of particular Person clicked.

Just List all Person in Master Page; Make dynamic link for detail page like,

<a href='view_details.php?person_id=<?=$person_id?>'>Vew Details</a>

So add up codes in view_details.php that will utilise this $_GET variable 'person_id' to access the information of it from the database via query; you will access it like $_GET['person_id']... something like that. I am assuming person_id as primary key. Surely you are begining stuffs in PHP. Gud luck! Check this , I guess they are giving source code also.

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