bo$$ Posted April 4, 2009 Share Posted April 4, 2009 Im making a simple "age verification" page, using $_GET & IF but I am getting a syntax error; "Parse error: syntax error, unexpected T_IF in /home/.../public_html/verifyage.php on line 12" I am a virgin to PHP and don't know what that error means here is the code: <html> <head><title>$GET Test</title></head> <body> <form action="verifyage.php" method="get"> Name:<input type="text" name="name" /> Age:<input type="text" name="age" /> <input type="submit" /> </form> <br> <?php $age = $_GET["age"] if ($age < 18) { echo "You are not old enough to enter this site."; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/152491-what-am-i-doing-wrong-here-if-blocks/ Share on other sites More sharing options...
jonsjava Posted April 4, 2009 Share Posted April 4, 2009 <html> <head><title>$GET Test</title></head> <body> <form action="verifyage.php" method="get"> Name:<input type="text" name="name" /> Age:<input type="text" name="age" /> <input type="submit" /> </form> <br> <?php $age = $_GET["age"]; //forgot the ";" if ($age < 18) { echo "You are not old enough to enter this site."; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/152491-what-am-i-doing-wrong-here-if-blocks/#findComment-800881 Share on other sites More sharing options...
bo$$ Posted April 4, 2009 Author Share Posted April 4, 2009 <html> <head><title>$GET Test</title></head> <body> <form action="verifyage.php" method="get"> Name:<input type="text" name="name" /> Age:<input type="text" name="age" /> <input type="submit" /> </form> <br> <?php $age = $_GET["age"]; //forgot the ";" if ($age < 18) { echo "You are not old enough to enter this site."; } ?> </body> </html> Wow, that was stupid of me, thanks. But I am still getting the same error. Does the code seem valid? Link to comment https://forums.phpfreaks.com/topic/152491-what-am-i-doing-wrong-here-if-blocks/#findComment-800890 Share on other sites More sharing options...
jonsjava Posted April 4, 2009 Share Posted April 4, 2009 no errors Link to comment https://forums.phpfreaks.com/topic/152491-what-am-i-doing-wrong-here-if-blocks/#findComment-800898 Share on other sites More sharing options...
bo$$ Posted April 4, 2009 Author Share Posted April 4, 2009 Lol, nevermind. Put the ";" on the wrong line. Link to comment https://forums.phpfreaks.com/topic/152491-what-am-i-doing-wrong-here-if-blocks/#findComment-800910 Share on other sites More sharing options...
bo$$ Posted April 4, 2009 Author Share Posted April 4, 2009 Ok, new question. In the IF ($age < 18) { echo "You must be 18 or older to enter this site."; } Is there anyway for that echo to hide until the the form submits? Basically what I mean is when it $_GETs the age, and its less than 18, is there anyway for that echo to ONLY execute if that statement is true? Because when I go to the page, the echo is there beforehand. Thanks for all your help Link to comment https://forums.phpfreaks.com/topic/152491-what-am-i-doing-wrong-here-if-blocks/#findComment-800921 Share on other sites More sharing options...
xtopolis Posted April 4, 2009 Share Posted April 4, 2009 <html> <head><title>$_GET Test</title></head> <body> <?php if(isset($_GET['age'])) { $age = intval($_GET["age"]); if ($age < 18) { echo "You are not old enough to enter this site."; }else{ //user is old enough, do something else } }else{ ?> <form action="verifyage.php" method="get"> Name:<input type="text" name="name" /> Age:<input type="text" name="age" /> <input type="submit" /> </form> <br> <?php } ?> </body> </html> Assuming the page is called verifyage.php Link to comment https://forums.phpfreaks.com/topic/152491-what-am-i-doing-wrong-here-if-blocks/#findComment-800925 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.