Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\freeelec2\deliveryupdate.php:179) in E:\xampp\htdocs\freeelec2\deliveryupdate.php on line 222

<?php
include('conn.php');
session_start();
if (!isset($_SESSION['Username'])){
header('location:index.php');
}
//


$tror=$_GET['tror'];
?>



<html>
<head>
<title>Delivery Update</title>
<script type="text/javascript" src="js/jquery.js"></script> 
        <script type="text/javascript" src="js/jquery.validate.js"></script> 
        <script language="javascript" src="js/cal2.js"></script>
        <script language="javascript" src="js/cal_conf2.js"></script>

        <script type="text/javascript">


        function Price(data) {

        document.getElementById("productprice").value = data.options[data.selectedIndex].id;

        newValue = (parseInt(document.form.bottles.value) * parseInt(document.form.price.value)); 
        document.form.total.value = newValue;

        }

        function computetotal() {

        newValue = (parseInt(document.form.price.value) * parseInt(document.form.deliver.value)); 
        document.form.total.value = newValue;

        }


        function computecustody() {

        newValue = (parseInt(document.form.deliver.value) - parseInt(document.form.return.value)); 
        document.form.custody.value = newValue;

        }

        function computecharge() {

        newValue = (parseInt(document.form.cash.value) - parseInt(document.form.total.value)); 
        document.form.charge.value = newValue;

        }



            $('document').ready(function(){

            $('#form').validate({
                    rules:{
                        "tror":{
                            required:true,
                            number:true,
                            maxlength:40
                        },

                        "name":{
                            maxlength:40
                        },
                        "price":{
                            required:true,
                            number:true
                        },
                        "deliver":{
                            required:true,
                            number:true
                        },
                        "return":{
                            required:true,
                            number:true
                        },
                        "total":{
                            required:true,
                            number:true
                        },
                        "date":{
                            required:true
                        }},

                    messages:{
                        "tror":{
                            required:"tror field is required",
                            number:"Please enter a valid number"
                        },
                        "price":{
                            required:"Price field is required select product first",
                            number:"Please enter a valid number"
                        },
                        "deliver":{
                            required:"Deliver field is required",
                            number:"Please enter a valid number"
                        },
                        "return":{
                            required:"Return field is required",
                            number:"Please enter a valid number"
                        },
                        "total":{
                            required:"Total field is required",
                            number:"Total must be a valid number"
                        }},

            })

        });
        </script> 
        <style type="text/css">
        .error{
        font-family:Arial, Helvetica, sans-serif;
        color:#FF0000;
        font-size:10px;
        padding-left:10px;
        }
        </style>
</head>

<?PHP

$sql = mysql_query('SELECT Product,Quantity,Price  FROM Inventory ORDER BY Price');
$product = array();
while ($row = mysql_fetch_array($sql)){
    $product[] = $row;
}
?>


<body onload="computetotal();computecustody();">
<form name="form" id="form" action="" method="post">
<h1>Update Delivery</h1>

<br />
<table width="449" border="0">

<?php $list_query=mysql_query("select * from delivery where TrOr='$tror'");
$rows=mysql_fetch_array($list_query);
?>

  <tr>
    <td width="107">TR/OR: </td>
    <td width="326"><input type="text" name="tror" maxlength="4" value="<?php echo $rows['TrOr'];  ?>" /></td>
    </tr>
  <tr>
    <td> Customer's Name: </td>
    <td><input type="text" name="name" maxlength="40" value="<?php echo $rows['Customers_Name'];  ?>" /></td>
    </tr>
      <tr>
   <td> Product: </td>
    <td>
    <select name="product" onchange="Price(this);computecustody()" onclick="computetotal();">
    <option value="<?php echo $rows['Product'];  ?>" selected="selected"><?php echo $rows['Product'];  ?></option>
    <?php
    foreach ($product as $product) {
    ?>
    <option value="<?php echo $product['Product']?>" id="<?php echo $product['Price']?>"><?php echo $product['Product'] . " Qty: " . $product['Quantity']?></option>
    <?php
    }
    ?>
    </select>
    </td>
    </tr>
    <tr>
  <tr>
    <td> Price: </td>
    <td><input id="productprice" onchange="computetotal" readonly type="text" name="price" /></td>
    </tr>
  <tr>
    <td> Deliver: </td>
    <td><input type="text" onchange="computecustody();computetotal();" name="deliver" value="<?php echo $rows['Deliver']; ?>" /></td>
    </tr>
  <tr>
    <td> Return: </td>
    <td><input type="text" onchange="computecustody();computetotal();" name="return" value="<?php echo $rows['xReturn']; ?>" /></td>
    </tr>
  <tr>
    <td> Custody: </td>
    <td><input readonly type="text" name="custody" value="<?php echo $rows['Custody']; ?>" /></td>
    </tr>
      <tr>
    <td> Total: </td>
    <td><input readonly type="text" onchange="computecharge()" name="total" /></td>
    </tr>
    <tr>
    <td> Cash: </td>
    <td><input type="text" onchange="computecharge()" name="cash" value="<?php echo $rows['Cash']; ?>" /></td>
    </tr>
    <tr>
    <td> Charge: </td>
    <td><input readonly type="text" name="charge" value="<?php echo $rows['Charge']; ?>" /></td>
    </tr>
</table>

<input type="submit" name="Update" value="Update">
</form>
</body>

<?php 

if (isset($_POST['Update'])){

$tror=$_POST['tror'];
$name=$_POST['name'];
$product=$_POST['product'];
$deliver=$_POST['deliver'];
$return=$_POST['return'];
$custody=$_POST['custody'];
$cash=$_POST['cash'];
$charge=$_POST['charge'];


mysql_query("update delivery set TrOr='$tror',Customers_Name='$name',Product='$product',Deliver='$deliver',Return='$return',Custody='$custody',Cash='$cash',Charge='$charge' where TrOr='$tror'");
header('location:delivery.php');

}
?>

</html>

I'm pretty sure a header function has to be before the HTML, so you could use a meta refresh, or a javascript redirect instead:

JS:

window.location.href = 'http://www.example.com/';

HTML:

<meta http-equiv="refresh" content="0;http://www.example.com/" />

help

This is known as a white space issue. Somewhere in the code white space is getting outputted. Try using ob_start() after session_start() to flush to your code. I would also recommend taking your database code out from under <head> and move to top of the page into a function.

Example:

function get_product_data()
{

    $sql = mysql_query('SELECT Product,Quantity,Price FROM Inventory ORDER BY Price');
    $product = array();
    while ($row = mysql_fetch_array($sql)){
        $product[] = $row;
    }

    return $row;
}

So now when you need to get product data you call your function. This will eleminate some of the white space you have under the head block of code.

Member Avatar for diafol

first header is fine.

header('location:delivery.php');

This is the problem. You've got html output before it, so it will raise an error.

<?php 
if (isset($_POST['Update'])){
$tror=$_POST['tror'];
$name=$_POST['name'];
$product=$_POST['product'];
$deliver=$_POST['deliver'];
$return=$_POST['return'];
$custody=$_POST['custody'];
$cash=$_POST['cash'];
$charge=$_POST['charge'];
mysql_query("update delivery set TrOr='$tror',Customers_Name='$name',Product='$product',Deliver='$deliver',Return='$return',Custody='$custody',Cash='$cash',Charge='$charge' where TrOr='$tror'");
header('location:delivery.php');
}
?>

That code could go straight after the

if (!isset($_SESSION['Username'])){
header('location:index.php');
}
//

chunk. I can't see any reason why it has to go below the html.

Like I said... :p

tnx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.