foundherent Posted December 11, 2018 Share Posted December 11, 2018 (edited) Hello Team, My job changed a few years back but I'm once again trying to learn to become better with php. I wanted to catch up to where I was around this time a few years back and honestly the language is coming back quickly but the quirky bottle-neck errors are still lingering. Hoping someone can take a look at the simple page I created below - post/get/session globals do not seem to be working, additionally, the semicolon after echo command does not seem to end the php command on the semicolon(displays everything). It may be a browser or something more simple but am hoping someone can at least look at my code below to see if there are any red flags. <?php print_r($_GET); echo '<p>Hello World</p>'; ?> <html> <body> <h2>Campus Information</h2> <form action="campus_test_form.php" method="get"> Campus Name:<br> <input type="text" name="campus_name" required> <br> Campus Abbreviation:<br> <input type="text" name="campus_abbreviation" maxlength="8" required> <br> <input type="submit" value="Submit"> <input type="reset"> </form> </body> </html> Edited December 11, 2018 by foundherent Quote Link to comment Share on other sites More sharing options...
gw1500se Posted December 11, 2018 Share Posted December 11, 2018 (edited) You will be executing the print before you even display the page the first time. I'm assuming ' campus_test_form.php ' is this page. You need to put that in an if block. <?php if (isset($_GET)) { print_r($_GET); echo '<p>Hello World</p>'; /* You may want different html after the submit */ } else { ?> <!-- Your initial html code here --> <?php } ?> Edited December 11, 2018 by gw1500se Quote Link to comment Share on other sites More sharing options...
foundherent Posted December 11, 2018 Author Share Posted December 11, 2018 6 minutes ago, gw1500se said: <?php if (isset($_GET)) { print_r($_GET); echo '<p>Hello World</p>'; /* You may want different html after the submit */ } else { ?> <!-- Your initial html code here --> <?php } ?> This needs a semicolon (;). However, you will be executing the print before you even display the page the first time. I'm assuming ' campus_test_form.php ' is this page. You need to put that in an if block. Thank you this worked for the second part, which helped me realize another egregious error I was making thereby preventing the get from functioning at all. Thank you thank you! Quote Link to comment Share on other sites More sharing options...
Barand Posted December 11, 2018 Share Posted December 11, 2018 The principle is sound, however $_GET is always set. You need to check for a specific value if (isset($_GET['campus_name'])) { echo '<pre>' . print_r($_GET, true) . '</pre>'; // easier to read } Quote Link to comment Share on other sites More sharing options...
gw1500se Posted December 11, 2018 Share Posted December 11, 2018 Oops. I forgot that. I stand corrected. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.