firedrop84 Posted March 29, 2006 Share Posted March 29, 2006 I am just wonding where is the error that i got as the if and else condition it's not working. I dont know why?!??!here is the code if ($HealthCover == "No") { print "It has been passed to NO"; if($achievement == "Toning" && $Gender == "Male") { print ("Men Transformation"); } elseif ($achievement == "Toning" && $Gender == "Female") { print "Womens Transformation"; } elseif ($achievement == "MuscleGain" && $Gender == "Male") { print "Mens muscle building"; } elseif ($achievement == "WeightGain" && $Gender == "Female") { print "Womens Body Shaping"; } else { header('Location: EnquiryForm.php'); } Quote Link to comment Share on other sites More sharing options...
AV1611 Posted March 29, 2006 Share Posted March 29, 2006 [!--quoteo(post=359639:date=Mar 29 2006, 07:56 AM:name=firedrop)--][div class=\'quotetop\']QUOTE(firedrop @ Mar 29 2006, 07:56 AM) [snapback]359639[/snapback][/div][div class=\'quotemain\'][!--quotec--]I am just wonding where is the error that i got as the if and else condition it's not working. I dont know why?!??!here is the code if ($HealthCover == "No") {<-----------------------------------------where is the close for this open brace????? print "It has been passed to NO"; if($achievement == "Toning" && $Gender == "Male") { print ("Men Transformation"); } elseif ($achievement == "Toning" && $Gender == "Female") { print "Womens Transformation"; } elseif ($achievement == "MuscleGain" && $Gender == "Male") { print "Mens muscle building"; } elseif ($achievement == "WeightGain" && $Gender == "Female") { print "Womens Body Shaping"; } else { header('Location: EnquiryForm.php'); }[/quote] Quote Link to comment Share on other sites More sharing options...
nikhilthecool Posted March 29, 2006 Share Posted March 29, 2006 as far as i know, u cannot echo or print anything before the header.. jus confirm it.thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted March 29, 2006 Share Posted March 29, 2006 You might try indenting your code so its readbale. You where missing a curly brace.[code]if ($HealthCover == "No") { print "It has been passed to NO"; if($achievement == "Toning" && $Gender == "Male") { print ("Men Transformation"); } elseif ($achievement == "Toning" && $Gender == "Female") { print "Womens Transformation"; } elseif ($achievement == "MuscleGain" && $Gender == "Male") { print "Mens muscle building"; } elseif ($achievement == "WeightGain" && $Gender == "Female") { print "Womens Body Shaping"; }} else { header('Location: EnquiryForm.php');}[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 29, 2006 Share Posted March 29, 2006 Since curly braces are not required when the statement block that is contained by them is only one statement, most of the braces can be removed:[code]<?phpif ($HealthCover == "No") { print "It has been passed to NO"; if($achievement == "Toning" && $Gender == "Male") print "Men Transformation"; elseif ($achievement == "Toning" && $Gender == "Female") print "Womens Transformation"; elseif ($achievement == "MuscleGain" && $Gender == "Male") print "Mens muscle building"; elseif ($achievement == "WeightGain" && $Gender == "Female") print "Womens Body Shaping";} else header('Location: EnquiryForm.php');?>[/code]You can also do away with the if/elseif by using a switch() statement:[code]<?phpif ($HealthCover == "No") { print "It has been passed to NO"; switch ($achievment) { case "Toning": if($Gender == "Male") print "Men Transformation"; if($Gender == "Female") print "Womens Transformation"; break; case "MuscleGain": if($Gender == "Male") print "Mens muscle building"; break; case "WeightGain": if($Gender == "Female") print "Womens Body Shaping"; break; }} else header('Location: EnquiryForm.php');?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
firedrop84 Posted March 29, 2006 Author Share Posted March 29, 2006 thanx for all the replies.my code still doesn't work as all the variables that I have it comes from a text file. then it puts them into an array after that into different variable names. Finally use the the print statment.I have used the code that ken adviced me and I have used before the if a print just to test what is inside the HealthCover variable. It has No varaible. but it doesnt go throught the if statment it goes staright to else. anybody got any idea why its happening like that. $Gender = $Data[1]; $achievement = $Data[2]; $Programs = $Data[3]; $WhatAchieve = $Data[4]; $WhenExercise = $Data[5]; $ComeToGym = $Data[6]; $IndoorsOutdoors = $Data[7]; $HowMuch = $Data[8]; $HealthCover = $Data[9]; print "$HealthCover"; if ($Data[9] == "No") { print "It has been passed to NO"; switch ($achievment) { case "Toning": if($Gender == "Male") print "Men Transformation"; if($Gender == "Female") print "Womens Transformation"; break; case "MuscleGain": if($Gender == "Male") print "Mens muscle building"; break; case "WeightGain": if($Gender == "Female") print "Womens Body Shaping"; break; }} else print "Didn't Read the if"; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 29, 2006 Share Posted March 29, 2006 Are you sure the last value is in $Data[9]? Array indices start at 0 in PHP. After putting you data into the array, dump it to the screen using the following code:[code]<?php echo '<pre>' . print_r($Data,true). '</pre>'; ?>[/code]and see what you're really dealing with.Ken Quote Link to comment Share on other sites More sharing options...
firedrop84 Posted March 29, 2006 Author Share Posted March 29, 2006 this is what I thought first. I used already the print_r and I suprised that the first element in the array was 1. I dont know why. Then, I displayed the $HealthCover variable and the value of it was as well No. so that means it's correct. ??!!? strange error I think :) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 29, 2006 Share Posted March 29, 2006 Can you post the code you use to read the data and populate the array? Also, what is the format of the data file?Ken Quote Link to comment Share on other sites More sharing options...
firedrop84 Posted March 29, 2006 Author Share Posted March 29, 2006 I dont know why I cann't post the code. it's display error 403 and it's saying you cannot view this page when I click on replay the post Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 29, 2006 Share Posted March 29, 2006 There are some problems posting code on this forum when the code contains filesystem function. In order to get around this, try putting an illegal character in the function name like "f.open()".Ken 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.