Jump to content

Newbie post of the year, guessing fundamental syntax error


foundherent

Recommended Posts

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>

Link to comment
Share on other sites

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
}
?>

 

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.