<?php
////////////////////////////
////////////Kharcha Section
////////////////////////////
        $kid = 0;
        if(isset($_POST['kharcha_btn'])){

        if(!empty( $_POST['karaya'] ) && !empty( $_POST['custom'] ) && !empty( $_POST['store-fees'] ) 
            && !empty( $_POST['market-fees'] ) && !empty( $_POST['commision'] ) && !empty( $_POST['mazdoori'] )
            && !empty( $_POST['wapsi-khracha'] ) && !empty( $_POST['munshiyana'] ) && !empty( $_POST['daktar'] )
            && !empty( $_POST['kham-bekri'] ) && !empty( $_POST['jumla_kharch'] ) && !empty( $_POST['pukhta-bekri'] )){ 

            $karaya = intval($_POST['karaya']);
            $custom = intval($_POST['custom']);
            $storeFees = intval($_POST['store-fees']);
            $marketFees = intval($_POST['market-fees']);
            $commision = intval($_POST['commision']);
            $mazdoori = intval($_POST['mazdoori']);
            $wapsiKharcha = intval($_POST['wapsi-khracha']);
            $munshiyana = intval($_POST['munshiyana']);
            $daktar = intval($_POST['daktar']);
            $khamBekri = intval($_POST['kham-bekri']);
            $jumlaKharch = intval($_POST['jumla_kharch']);
            $pukhtaBekri = intval($_POST['pukhta-bekri']);

            $qry = "INSERT INTO `kharcha`(`KharchaId`
                                        , `Karaya`
                                        , `Custom`
                                        , `StoreFees`
                                        , `MarketFees`
                                        , `Comission`
                                        , `Mazdoori`
                                        , `WapsiKharcha`
                                        , `Munshiana`
                                        , `Daktaar`
                                        , `KhaamBekri`
                                        , `JumlaKharch`
                                        , `PukhtaBekri`) 
                                    VALUES ( null
                                            ,$karaya
                                            ,$custom
                                            ,$storeFees
                                            ,$marketFees
                                            ,$commision
                                            ,$mazdoori
                                            ,$wapsiKharcha
                                            ,$munshiyana
                                            ,$daktar
                                            ,$khamBekri
                                            ,$jumlaKharch
                                            ,$pukhtaBekri
                                            )";

            $result = mysql_query($qry) or die("error: ". mysql_error());
            $kharchaid = mysql_insert_id();
                echo "<p class='red-info'> Record Saved! </p>";
            header("gotka.php?kid=$kharchaid");
            }else{
                echo "<p class='red-info'>Please enter all the fields correctly! </p>";
            }// end of if-statement

    }// end of kharcha section
?>

<form action="gotka.php" method="POST">
<fieldset style="padding-left: 2px; padding-right: 2px; padding-top:0px; ">
       <legend><span class="urdu20">خرچہ سیکشن</span></legend>

            <p class="abc"> 
                  <input class="toAdd" type="text" name="karaya" id="karaya" size="17" />
                  <label for="karaya"><span class="urdu20">کرایہ:</span></label>

            </p>
            <p class="abc"> 
                  <input class="toAdd" type="text" name="custom" id="custom" size="17" />
                  <label for="custom"><span class="urdu20">کسٹم:</span></label>

            </p>

            <p class="abc"> 
                  <input class="toAdd" type="text" name="store-fees" id="store-fees" size="12" />
                  <label for="store-fees"><span class="urdu20">سٹور فیس:</span></label>

            </p>
            <p class="abc"> 
                  <input class="toAdd" type="text" name="market-fees" id="market-fees" size="10" />
                  <label for="market-fees"><span class="urdu20">مارکیٹ فیس:</span></label>

            </p>
            <p class="abc" > 
                  <select class="toAdd" name="commision" id="commision" style="margin-right: 10px;">
                              <option value="7">--- 7% ---</option>
                              <option value="8">--- 8% ---</option>
                              <option value="9">--- 9% ---</option>      
                  </select>

                  <label for="commision" style="margin-right: 30px;"><span class="urdu20">کمیشن :</span></label>

            </p>
            <p class="abc"> 
                  <input class="toAdd" type="text" name="mazdoori" id="mazdoori" size="15" />
                  <label for="mazdoori"><span class="urdu20">مزدوری:</span></label>

            </p>
            <p class="abc"> 
                  <input class="toAdd" type="text" name="wapsi-khracha" id="wapsi-khracha" size="11" />
                  <label for="wapsi-khracha"><span class="urdu20">واپسی خرچہ:</span></label>

            </p>
            <p class="abc"> 
                  <input class="toAdd" type="text" name="munshiyana" id="munshiyana" size="14" />
                  <label for="munshiyana"><span class="urdu20">منشیانہ:</span></label>

            </p>
            <p class="abc"> 
                  <input class="toAdd" type="text" name="daktar" id="daktar" size="16" />
                  <label for="daktar"><span class="urdu20">ڈاکتار:</span></label>

            </p>
            <p class="abc"> 
                  <input type="text" name="kham-bekri" id="kham-bekri" size="12" />
                  <label for="kham-bekri"><span class="urdu20">خام بیکری:</span></label>

            </p>

            <p class="abc"> 
                  <input type="text" name="jumla_kharch" id="jumla_kharch"  size="10" />
                  <label for="jumla_kharch"><span class="urdu20">جملہ خرچ:</span></label>

            </p>

            <p class="abc">
                  <input type="text" name="pukhta-bekri" id="pukhta-bekri" size="10" />
                  <label for="pukhta-bekri"><span class="urdu20">پختہ بیکری:</span></label>

            </p>

            <p class="abc">
                  <input type="submit" name="kharcha_btn" id="kharcha_btn" value="Save"/>
            </p>
      </fieldset>
</form>

You should not echo any output before the header command. Remove line 56:

echo "<p class='red-info'> Record Saved! </p>";

so the headers can be sent. This command is pointless anyway since the page would get redirected.

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.