Jump to content

IF ELSE LOGIC PROBLEM


sonved2004

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/
Share on other sites

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

<!--

Link to comment
https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465699
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465701
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-465702
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/90850-if-else-logic-problem/#findComment-466660
Share on other sites

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.