header location php

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\village\village_borrownamepay.php:6) in C:\wamp\www\village\village_borrownamepay.php on line 51

after I put  

header('Location: http://127.0.0.1');  
inline 51
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<title>H2"@49I</title>
<style type="text/css">
 
<?php require_once('../Connections/village.php'); ?>
<?php 
 
if(isset($_POST['submit']))
{
echo "<BR>";
$MinimumPay = $_POST['MinimumPay'] ;
$NoOfMonth = $_POST['NoOfMonth'] ;
$Interrest = $_POST['Interrest'] ;
$AccNo = $_POST['AccNo'] ;
$payment = $_POST['payment'] ;
$balanceloan = $_POST['balanceloan'] ;
$wname = $_POST['wname'] ;
$totalinterrest = $_POST['totalinterrest'] ;
$totalfine = $_POST['totalfine'] ;
 
$Newbalanceloan = $balanceloan + $MinimumPay - $payment;
$payprincipal = $payment - $MinimumPay ;
 
    if( $MinimumPay  >  $payment  ) 
	{  echo " 8I-H2"1IH3   $MinimumPay 2";
	echo "<input name='Cancel' type='button' id='button2' value='cancel' onClick='history.go(-1)' /> " ;
	exit();
	}
    if( $NoOfMonth < 1  ) 
	{  echo "8H2"A%I'";
	echo "<input name='Cancel' type='button' id='button2' value='cancel' onClick='history.go(-1)' /> " ;
	exit();
	}	
    if( $payment < 0  ) 
	{  echo "@%5H#-4% ";
	echo "<input name='Cancel' type='button' id='button2' value='cancel' onClick='history.go(-1)' /> " ;
	exit();
	}		
	
$updateSQL = "UPDATE balanceborow SET DateBalance=now(), amout=$Newbalanceloan WHERE wid=$AccNo" ;
mysql_select_db($database_village, $village);
$Result1 = mysql_query($updateSQL, $village) or die(mysql_error());
 
$insertSQL = "INSERT INTO hpay (MemberidH, membernameH, htype, amount, date) VALUES ('$AccNo', '$wname', 'pin', '$totalinterrest', now()),('$AccNo', '$wname', 'pfi', '$totalfine', now()),('$AccNo', '$wname', 'ppr', '$payprincipal', now())" ;
mysql_select_db($database_village, $village);
$Result1 = mysql_query($insertSQL, $village) or die(mysql_error());
 
header('Location: http://127.0.0.1');
 
 
	}
else 
{
 
 
 
$AccNo = $_POST['AccNo'];
 
 
 
mysql_select_db($database_village, $village);
$query_rec_borrowpay = "SELECT balanceborow.wid, balanceborow.wname, balanceborow.amout,  CEILING(balanceborow.amout*.02) AS Interrest, balanceborow.DateBalance, balanceborow.amout, Round(DATEDIFF( NOW() , balanceborow.DateBalance)/30, 0) As MonthNos, (Round(DATEDIFF( NOW() , balanceborow.DateBalance)/30, 0)*2-1)*CEILING(balanceborow.amout*.02) As MiniPay FROM balanceborow WHERE balanceborow.wid ='$AccNo'   ";
$rec_borrowpay = mysql_query($query_rec_borrowpay, $village) or die(mysql_error());
$row_rec_borrowpay = mysql_fetch_assoc($rec_borrowpay);
$totalRows_rec_borrowpay = mysql_num_rows($rec_borrowpay);
 
mysql_select_db($database_village, $village);
mysql_db_query($database_village,"SET NAMES tis620"); 
$query_Recordset1 = "SELECT listname.ID, listname.Name FROM listname WHERE listname.ID = '$AccNo' ";
$Recordset1 = mysql_query($query_Recordset1, $village) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
 
<!--
.style1 {
	font-size: xx-large;
	color: #000066;
}
-->
</style>
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <label></label>
  <h1>
    <label></label>
  </h1>
  <table width="531" height="189" border="1">
    <tr>
      <td width="167" height="47">ACCOUNT NO</td>
      <td width="348" colspan="2"><?php echo $row_rec_borrowpay['wid']; ?></td>
    </tr>
    <tr>
      <td height="49">ACCOUNT NAME</td>
      <td colspan="2"><?php echo $row_rec_borrowpay['wname']; ?></td>
    </tr>
    <tr>
      <td height="49">Interrest</td>
      <td colspan="2"><?php echo $row_rec_borrowpay['Interrest']; ?></td>
    </tr>
    <tr>
      <td height="49">Bowrow Amount</td>
      <td colspan="2"><?php echo $row_rec_borrowpay['amout']; ?> baht Date <?php echo $row_rec_borrowpay['DateBalance']; ?></td>
    </tr>
    <tr>
      <td height="49">-@5I" /H2#1</td>
      <td><?php $Tolmonth = $row_rec_borrowpay['MonthNos'];
	            $onemonthinterrest = $row_rec_borrowpay['Interrest'];
				$totalinterrest = $Tolmonth*$onemonthinterrest ;
				$totalfine = ($Tolmonth-1)* $onemonthinterrest ;
	             if ($totalinterrest < 0 ){$totalinterrest =0;}
				 if ($totalfine < 0 ){$totalfine=0;}
	            echo $totalinterrest ; ?></td>
      <td><?php echo $totalfine ;?></td>
    </tr>
    <tr>
      <td height="49">No of month</td>
      <td colspan="2"><?php echo $row_rec_borrowpay['MonthNos']; ?></td>
    </tr>
    <tr>
      <td height="49">Minimum Payment</td>
      <td colspan="2"><h1 class="style1"><?php
$MiniPay = $row_rec_borrowpay['MiniPay'];
if ($MiniPay < 0 ){$MiniPay =0;}
echo "$MiniPay";?></h1></td>
    </tr>
    <tr>
      <td>BAHT </td>
      <td colspan="2"><span id="sprytextfield1">
      <input name="payment" type="text" class="style1" id="textfield" />
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2"><label>
        <input type="submit" name="submit" id="button" value="Submit" />          
        <input name="Cancel" type="button" id="button2" value="cancel" onClick="history.go(-1)" />
       
        <input name="MinimumPay" type="hidden" value="<?php echo $MiniPay; ?>" />
        <input name="NoOfMonth" type="hidden" value="<?php echo $row_rec_borrowpay['MonthNos']; ?>" />
        <input name="Interrest" type="hidden" value="<?php echo $row_rec_borrowpay['Interrest']; ?>" />
        <input name="AccNo" type="hidden" value="<?php echo $AccNo; ?>" />
        <input name="balanceloan" type="hidden" value="<?php echo $row_rec_borrowpay['amout']; ?>" />
        <input name="wname" type="hidden" value="<?php echo $row_rec_borrowpay['wname']; ?>" />
        <input name="totalinterrest" type="hidden" value="<?php echo $totalinterrest; ?>" />
        <input name="totalfine" type="hidden" value="<?php echo $totalfine ; ?>" />
 
 
      
      
      </label></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <label></label>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "integer", {validateOn:["change"]});
//-->
</script>
</body>
</html>
 
 
<?php
 
 
mysql_free_result($rec_borrowpay);
mysql_free_result($Recordset1);
}
?>

Open in new window

teeraAsked:
Who is Participating?
 
gamebitsConnect With a Mentor Commented:
You cannot send any html to the browser before you send headers information, not even a blank space
0
 
gamebitsCommented:
You can buffer the output by using ob_start at the beginning of the page and ob_flush after the header location
0
 
teeraAuthor Commented:
How can i send header information
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Julian MatzConnect With a Mentor Joint ChairpersonCommented:
You can send your header information before anything is output to the browser. As mentioned, this includes any text or characters, including whitespace.

A workaround would be to use the PHP output buffer as previously mentioned. To do this you would place the following at the top of your script:

ob_start();

...and this at the bottom of your script:

ob_end_flush();

This will prevent any output to the browser until all your code is executed, therefore allowing you to use headers throughout your entire script. Another advantage is that using the output buffer often increase the time in which a page loads in a browser as all the output is sent at once.

Sending the following headers would send a 301 (moved permanently) status code to the browser, redirect the page to the given URL, and end execution of the current script:

<?php
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://www.experts-exchange.com/" );
header( "Connection: close" );
exit;
?>
0
 
gamebitsCommented:
header('Location: http://127.0.0.1');  this is part of the header information it as to be sent before any html output.
0
 
Julian MatzConnect With a Mentor Joint ChairpersonCommented:
The reason for the error is that you have your HTML at the very top of the page.

To resolve the problem, just place the following at the very start of your page on the first line:

<?php
ob_start();
?>

Then insert "ob_end_flush();" at the very bottom like so:

<?php

mysql_free_result($rec_borrowpay);
mysql_free_result($Recordset1);
}
ob_end_flush();
?>
0
 
Rok-KraljConnect With a Mentor Commented:
Just put ob_start(); above LINE 5.

You don't have to put ob_end_flush(); as WD before me said.
0
 
Julian MatzJoint ChairpersonCommented:
>> Just put ob_start(); above LINE 5.
How will that work? ob_start() needs to be called before output is started.

>> You don't have to put ob_end_flush(); as WD before me said.
Without using ob_end() or on_end_flush(), the output buffer will not be sent to browser and cleared.

Here's the manual:
http://php.net/ob_start
0
 
Rok-KraljCommented:
Both points wrong:

1. By error, output started in line 6:
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\village\village_borrownamepay.php:6) in C:\wamp\www\village\village_borrownamepay.php on line 51

2. ob_end_flush(); is called automatically, if there is a pending buffer.
0
 
Julian MatzJoint ChairpersonCommented:
>> Both points wrong:

My points were not both "wrong".

"How will that work?" (This is a question).

"ob_start() needs to be called before output is started." (This is in fact correct, I was just going by the line numbers of the attached code snippet, where the output starts on line #1).

Yes, I was wrong on 2. Apparently it does call the function automatically, but it's my understanding that you need to call ob_end_flush() when using multiple output callback functions. In any case, it is not wrong to use ob_end_flush() to end the output buffering.
0
 
Rok-KraljConnect With a Mentor Commented:
If there are multiple output callback functions, then ob_end_flush in called in reverse order (function started first, ended last)...
0
All Courses

From novice to tech pro — start learning today.