sonved2004 Posted February 13, 2008 Share Posted February 13, 2008 Hi, New to PHP but experienced programmer. I need support on form validation. my code goes like this - $URL="welcome.php" if($flag <>"OK"){ echo "<center>$msg <br> <input type='button' value='Retry' onClick='history.go(-1)'></center>"; }else{header ("Location: $URL"); } I expect that if the form validation found OK, (this part ->else{header ("Location: $URL") a new page will be opened, informing user that form has been submitted. I have three pages like this - 1.Form.php 2.fvalidate.php 3.welcome.php my form action opens fvalidate.php and if all is well it should take automatically to welcome.php Can anybody help how to complete this else part in the above script? ??? Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/ Share on other sites More sharing options...
sKunKbad Posted February 13, 2008 Share Posted February 13, 2008 I don't believe that <> will work as a comparison operator, try: if($flag == 'OK'){ } Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465649 Share on other sites More sharing options...
btherl Posted February 13, 2008 Share Posted February 13, 2008 What happens when you run your code? Edit: <> means "not equal", same meaning as !=, so it's ok to use. Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465670 Share on other sites More sharing options...
unknownsheep Posted February 13, 2008 Share Posted February 13, 2008 Nevermind, im tired :-X Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465671 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 In what way is it not working now? note: you should add exit; after your header statement. Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465681 Share on other sites More sharing options...
sonved2004 Posted February 13, 2008 Author Share Posted February 13, 2008 thanks for reply but now I am getting this msg... Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\success\fvalidate.php:2) in C:\wamp\www\success\fvalidate.php on line 53 how to avoid this? Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465695 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 It means you have already outputted something to the browser before your location header. It may be as simple as a space. Can you post the top of your code down to the header? Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465698 Share on other sites More sharing options...
sonved2004 Posted February 13, 2008 Author Share Posted February 13, 2008 yes. following 12 lines are at the top of page.. <html> <?php $URL="welcome.php"; if($flag <>"OK"){ echo "<center>$msg <br> <input type='button' value='Retry' onClick='history.go(-1)'></center>"; }else{header ("Location: $URL"); exit; } ?> <script language="JavaScript" type="text/JavaScript"> <!-- Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465699 Share on other sites More sharing options...
carobee Posted February 13, 2008 Share Posted February 13, 2008 thanks for reply but now I am getting this msg... Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\success\fvalidate.php:2) in C:\wamp\www\success\fvalidate.php on line 53 how to avoid this? use ob_start(); ----ur code--- ob_flush(); http://in2.php.net/ob_start Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465701 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 Don't do that, ob_start() isn't recommended. Change your code to this: <?php $URL="welcome.php"; if($flag <>"OK"){ echo "<html><center>$msg <input type='button' value='Retry' onClick='history.go(-1)'></center>"; }else{header ("Location: $URL"); exit; } ?> <script language="JavaScript" type="text/JavaScript"> <!-- Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465702 Share on other sites More sharing options...
sonved2004 Posted February 13, 2008 Author Share Posted February 13, 2008 thanks Haku... it worked. Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465709 Share on other sites More sharing options...
btherl Posted February 13, 2008 Share Posted February 13, 2008 Don't do that, ob_start() isn't recommended. Isn't recommended by who, and why? Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-466385 Share on other sites More sharing options...
carobee Posted February 14, 2008 Share Posted February 14, 2008 Don't do that, ob_start() isn't recommended. not recommended???????????????? ??? Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-466652 Share on other sites More sharing options...
kenrbnsn Posted February 14, 2008 Share Posted February 14, 2008 When you use ob_start() to hide header problems, you're not fixing the problem, just hiding it. You should fix the problem, which is probably due to a logic or program flow problem. I, for one, have never understood why anyone would want to put out anything to the browser and then jump to another page. Ken Quote Link to comment https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-466660 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.