Jump to content

What am I doing wrong here? (IF blocks)


bo$$

Recommended Posts

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

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

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

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

<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

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.