Set php variable from text box value

Hello Experts;

I am setting a variable when page 1 is opened for transfer and display on page 2:

// Set session variables
$_SESSION['bbc2'] = "Two door cabinet";
No problem...

On the same page I have a text box for entering quantity which I want to transfer and display on page 2:

<form action = "" method = "POST">
Quantity: &nbsp; <input type="submit" name="submit" value="1" style="width:50px">
</form>
<?php
if(isset($_POST['submit'])) $_SESSION['qbbc2']="value";
?>

 I can't figure out how to retrieve the value from the text box and set the second vaiable $_SESSION['qbbc2'] to equal the text box value for tranfer and display on page 2.

Help would be greatly appreciated.

Thank you,
Visionetv
visionetvAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
This would be your form on page 1. You need to add a form field to enter the data.
<form action = "page2.php" method = "POST">
Quantity: &nbsp; <input type="text" name="qty" value="0">
<input type="submit" name="submit" value="1" style="width:50px">
</form>

Open in new window


Then on page2.php
if(isset($_POST['qty'])) $_SESSION['qbbc2']=$_POST['qty'];

Open in new window


This is a bit simplistic and you will want to verify the data which in this case is to make sure qty is an integer and perhaps within a certain range say 0 to 100?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
visionetvAuthor Commented:
Figured it out...

<form action="" method="POST">
<input type="text" name="qty">
<input type="submit" name="submit">
 </form>
<?php
if (isset($_POST['submit']))
 {
$quantity = $_POST['qty'];
}
?>
$_SESSION['qbbc2']= $quantity; sets the variable for transfer and display on page 2.
1
visionetvAuthor Commented:
Hi Scott;

Thank you I didn't see your post prior to my comment, your code is quite similar to what I used.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Yes, we posted at the same time.

Just remember to add some type of validation before doing anything with that qty number or any posted data.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.