Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

How to bring forward data to next php page

{FORM NAME ="form1" METHOD ="POST" ACTION ="testing2.php"} <?php $file1 = 424241; ?>

{Input type = 'Checkbox' Name ='checkbox1' value = '424241' uncheked } UserID

{INPUT TYPE = "Submit" Name = "Submit1" VALUE = "What ID"} {/FORM}

{?PHP if (isset($_POST['Submit1'])) { if (isset($_POST['checkbox1'])) { echo $chi = $_POST['checkbox1'] ;
} } ?}

Above is my code. Example when i select checkbox1 and the value is $file1 = 424241. how can i display the value of 424241 in testing2.php page? as once i click the submit button i will direct me to testing2.php <FORM NAME ="form1" METHOD ="POST" ACTION ="testing2.php">

I have replace the <> with {} aswhen i put < for HTML code > it will not display correctly.

Best Regard

Sorry i will update again my code seem like need to add some formatting

4 Answers

To get and print the value of the checkbox on the next page, you'd have something like this: <?php echo $_POST["checkbox1"].

That's assuming your form submits correctly.

http://www.php.net/manual/en/reserved.variables.post.php

Thanks Kevin really helpfull

Hi Kevin,

the 1st page of testing1.php it has looping 10 times to produce 10 checkbox and therefore my testing2.php also need to loop 10 times to echo out the checkbox value.

Let said the looping times is an x....how can i know both pages of .php having same looping? appreciate if you can give me an idea.

Best Regards

I don't understand. Is the value attribute for each checkbox on the first page going to change? Or are you going to have 10 checkboxes with the same value? Is each checkbox going to have a different name attribute as well?

Without really knowing what's going on, you could run the checkbox's through a php for loop, auto incrementing the name attribute by one, so the first would be "checkbox1" the second "checkbox2".

And than on page two you could run another for loop and save each checkbox value into an auto incrementing variable, so your for loop would output something like

$checkbox1_val = $_POST["checkbox1"];
$checkbox2_val = $_POST["checkbox2"}
...

I've never done that before, but I suppose it could work.

Thanks Kevin ..it work well