Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.