NEED HELP CREATING PHP SESSION

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ziaul1234
Forum Newbie
Posts: 7
Joined: Thu Sep 16, 2010 4:52 pm

NEED HELP CREATING PHP SESSION

Post 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
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Re: NEED HELP CREATING PHP SESSION

Post 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
ziaul1234
Forum Newbie
Posts: 7
Joined: Thu Sep 16, 2010 4:52 pm

Re: NEED HELP CREATING PHP SESSION

Post by ziaul1234 »

Thank you. It has really helped.
Post Reply