Variable persistence in PHP

我怕爱的太早我们不能终老 提交于 2019-12-02 02:34:01

I think you are looking for PHP's session handling stuff ...

As an example, first page:

session_start(); # start session handling.
$_SESSION['test']='hello world';
exit();

second page:

session_start(); # start session handling again.
echo $_SESSION['test']; # prints out 'hello world'

Behind the scenes, php has set a cookie in the users browser when you first call session start, serialized the $_SESSION array to disk at the end of execution, and then when it receives the cookie back on the next page request, it matches the serialised data and loads it back as the $_SESSION array when you call session_start();

Full details on the session handling stuff:

http://uk.php.net/manual/en/book.session.php

Around the add-button you are creating a second form. If you want to have the data within this form then you will have to create hidden input fields. Because you are sending a second form here. Or you are moving the add button up to the other form.

Or as others are mentioning.. Save the values into a session.

you could store them in a session

// first part of form, store name in session
$_SESSION['name'] = $_POST['name'];

// 2nd part of form, store in database
$name = mysql_real_escape_string($_SESSION['name']); 
$sql = "INSERT INTO table (name_column) VALUES ('$name');

You can also try using hidden forms variables to store the data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!