Jump to content

[SOLVED] if/then satement whats wrong?


creasign

Recommended Posts

hey firstly loving to stuff i am seeing here.. secondly i need some help...

 

i am trying to write an if then statement here is what i have or the bit with the problem !


// What to send

$email=mail($to,$subject,$message,$header);



// What to do when done


{
if trim($_POST['age'] < 18 echo "please Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue");

else

header("Location: http://www.wokinghambikeathon.co.uk/register2.php"); 

}

else {

echo "ERROR";

}

 

what i am trying to do is that if a user trys to register for the event and they are under 18 it will show a message for them to download the parentral consent form then continue .. i get the error unexpected T_STRING on line 119 (i have marked this line with 3 *'s )  i have tried many different aproaches but i am stumped .. any sugestions?

 

 

Link to comment
https://forums.phpfreaks.com/topic/145486-solved-ifthen-satement-whats-wrong/
Share on other sites

ur syntax is wrong...

try this

if trim($_POST['age'] < 18) {
    echo "please Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue";
}

new error ..  :(   

Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/wokingba/public_html/send_register.php on line 117

 


***  if trim($_POST['age'] < 18); {
    echo "please Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue";
}else{
header("Location: http://www.wokinghambikeathon.co.uk/register2.php");

}

 

thats what i have th *** marks the line the error is on .. its such a pain and i though i was half decent at php :-\

 

 

new error ..  :(   

Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/wokingba/public_html/send_register.php on line 117

 


***  if trim($_POST['age'] < 18); {
    echo "please Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue";
}else{
header("Location: http://www.wokinghambikeathon.co.uk/register2.php");

}

 

thats what i have th *** marks the line the error is on .. its such a pain and i though i was half decent at php :-\

 

 

 

Really easy one to fix, just comparing it to samshel's solution would solve the problem;

 

if trim($_POST['age'] < 18); {

 

should be

 

if (trim($_POST['age']) < 18) {

another error .. this is getting on my teets 

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/wokingba/public_html/send_register.php on line 118

 

 

  if trim($_POST['age'] < 18); {

***    echo "please Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue";

}else{

header("Location: http://www.wokinghambikeathon.co.uk/register2.php");

 

}

 

this little line is causing soo much problem i have been stairing at it for days everything i have tried conducts a new error!

another error .. this is getting on my teets 

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/wokingba/public_html/send_register.php on line 118

 

 

  if trim($_POST['age'] < 18); {

***    echo "please Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue";

}else{

header("Location: http://www.wokinghambikeathon.co.uk/register2.php");

 

}

 

this little line is causing soo much problem i have been stairing at it for days everything i have tried conducts a new error!

 

becuase you're not escaping the HTML tags in your echo...

 

Do it like this...

 

if trim($_POST['age'] < 18) {
   echo "please Download the parental consent form <a target=\"_blank\"  href=\"www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf\">here</a><br>then click <a href=\"www.wokinghambikeathon.co.uk/register2.php\">here</a> to continue";
}else{
   header("Location: http://www.wokinghambikeathon.co.uk/register2.php");

}

 

Also you had a semi colon next to your conditional statement, don't do that so i took it out.

if trim($_POST['age'] < 18) {
   echo "please Download the parental consent form <a target=\"_blank\"  href=\"www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf\">here</a><br>then click <a href=\"www.wokinghambikeathon.co.uk/register2.php\">here</a> to continue";
}else{
   header("Location: http://www.wokinghambikeathon.co.uk/register2.php");

}

 

Also you had a semi colon next to your conditional statement, don't do that so i took it out.

 

You're still missing something, namely in trim()

// Technically, you won't need trim()
if(trim($_POST['age']) < 18) {
   echo '{lease Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue';
   // I find it easiest to use single quotes on echo and double quotes in my html. 
   // it requires less escaping
}else{
   header("Location: http://www.wokinghambikeathon.co.uk/register2.php");
}

 

 

<?php



//set variables

// code by creativity in design



$name1 = trim($_POST['name1']);

$name2 = trim($_POST['name2']);

$sex = trim($_POST['sex']);

$dob = trim($_POST['DOB']);

$age = trim($_POST['age']);

$email = trim($_POST['email']);

$telephonenumber = trim($_POST['telephonenumber']);

$etelephonenumber = trim($_POST['etelephonenumber']);

$econtact = trim($_POST['econtact']);

$streetname1 = trim($_POST['streetname1']);

$streetname2 = trim($_POST['streetname2']);

$town = trim($_POST['town']);

$county = trim($_POST['county']);

$postcode = trim($_POST['postcode']);

$team = trim($_POST['team']);

$charity = trim($_POST['charity']);

$tshirt = trim($_POST['tshirt']);



//message structure



// Subject

$subject = "$name1, $name2, $charity"; 



// Main message

$message = "$name $name2

$sex

$dob

$age

$email

$telephonenumber

emergency contact details -

$etelephonenumber

$econtact

address -

$streetname1

$streetname2

$town

$county

$postcode

team - $team

charity - $charity

tshirt - $tshirt";



// Message header

$header="from: $name1 $name2 <$email>";



// Customer email

$to ='[email protected]';



// What to send

$email=mail($to,$subject,$message,$header);



// What to do when done

// Technically, you won't need trim()
if(trim($_POST['age']) < 18) {
   echo '{lease Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue';
   // I find it easiest to use single quotes on echo and double quotes in my html. 
   // it requires less escaping
}else{
   header("Location: http://www.wokinghambikeathon.co.uk/register2.php");

?>

 

 

thats the whole page ... although now there is a new error 

Parse error: syntax error, unexpected $end in /home/wokingba/public_html/send_register.php on line 125

 

this is the last line of code so what you have chnaged already seems to have done the trick just something else there .. before i tried to add in this end bit the whole code worked fine and sent the emails ect .. so i realy dont know

 

 

// Technically, you won't need trim()
if(trim($_POST['age']) < 18) {
   echo '{lease Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue';
   // I find it easiest to use single quotes on echo and double quotes in my html. 
   // it requires less escaping
}else{
   header("Location: http://www.wokinghambikeathon.co.uk/register2.php");

?>

 

Should be:

// Technically, you won't need trim()
if(trim($_POST['age']) < 18) {
   echo 'Please Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue';
   // I find it easiest to use single quotes on echo and double quotes in my html. 
   // it requires less escaping
}else{
   header("Location: http://www.wokinghambikeathon.co.uk/register2.php");
} // you were missing this!
?>

 

Edit: fixed typo with { instead of P ;)

You're missing a closing bracket before the last line...it should be:

 

// Technically, you won't need trim()
if(trim($_POST['age']) < 18) {
   echo '{lease Download the parental consent form <a target="_blank"  href="www.wokinghambikeathon.co.uk/documents/parentalconsentform.pdf">here</a><br>then click <a href="www.wokinghambikeathon.co.uk/register2.php">here</a> to continue';
   // I find it easiest to use single quotes on echo and double quotes in my html. 
   // it requires less escaping
}else{
   header("Location: http://www.wokinghambikeathon.co.uk/register2.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.