Page 1 of 1

NEED HELP CREATING PHP SESSION

Posted: Thu Sep 16, 2010 5:02 pm
by ziaul1234
I am learning PHP. Need a basic help. I want to create a html page where I input data. When confirmed key is pressed it will take to a php page where entered data wll be shown and there will be a edit button.I can easily do it upto this.

Now which I cant do is:
when edit button will be pressed it wil take to a different php page which is similar to first page but all input fields will be prefilled with the data entered and I will be able to edit the data.

If someone can help me giving an example of only one field, then it wil be great.

Thanks a lot

Re: NEED HELP CREATING PHP SESSION

Posted: Sat Sep 18, 2010 6:07 pm
by mecha_godzilla
Assuming you've captured the form values correctly you can then pre-populate the text fields using this sort of code:

Code: Select all

$my_value = $_POST['my_value'];

echo 'Your value is: <input type="text" name="my_value" value="' . $my_value . '" /><br />';
Alternatively, if you want to use sessions instead you need to add session_start() to the top of both pages, then on your first page do this:

Code: Select all

$_SESSION['my_value'] = $_POST['my_value']
then on your second page do this:

Code: Select all

$my_value = $_SESSION['my_value'];

echo 'Your value is: <input type="text" name="my_value" value="' . $my_value . '" /><br />';
Is that what you need?

HTH,

Mecha Godzilla

Re: NEED HELP CREATING PHP SESSION

Posted: Sun Sep 19, 2010 5:33 am
by ziaul1234
Thank you. It has really helped.