Any one can tell what is the wrong with here?

Discussion in 'PHP' started by Parallax, Mar 18, 2011.

  1. #1
    Here code is executing correctly. But echo word is not working..:(:(

    <?php
    $con1 = mysql_connect("localhost","root","")or die("Connection error");
    mysql_select_db("budjet")or die("cannot find the database");

    $sql = mysql_query("SELECT balance from dtotal",$con1);

    if (mysql_num_rows($sql)==0){

    echo "<p>There is no any records</p>";
    echo "<a href=value.php>click here</a>";
    }
    else
    {
    if(isset($_POST['date'])) {
    $date = $_POST['date'];
    $food = $_POST['food'];
    $transport = $_POST['transport'];
    $reload = $_POST['reload'];
    $other = $_POST['other'];
    $income = $_POST['income'];

    $numrows = mysql_num_rows($sql);
    $dbalance = mysql_result($sql,($numrows-1),"balance");

    $e_total = ($food+$transport+$reload+$other);
    $balance = $dbalance+$income-$e_total;

    echo "<br>";
    echo "<h3>Yesterday balance : Rs.".$dbalance."</h3>";

    echo "<br>";
    echo "<h3>Today total expence : Rs.".$e_total."</h3>";

    echo "<br>";
    echo "<h3>Today total income : Rs.".$income."</h3>";

    echo "<br>";
    echo "<h3><font color = red>".$date." Balance is : Rs.".$balance."</h3></font>";

    $dexpence = "INSERT INTO dexpence(date,food,transport,reload,other)VALUES('$date','$food','$transport','$reload','$other')";
    $dtotal = "INSERT INTO dtotal(e_total,i_total,balance)VALUES('$e_total','$income','$balance')";
    $dincome = "INSERT into dincome(date,income)VALUES('$date','$income')";

    header("location:budget.php");

    mysql_query($dexpence,$con1);
    mysql_query($dtotal,$con1);
    mysql_query($dincome,$con1);

    }}

    mysql_close($con1);
    ?>
     
    Parallax, Mar 18, 2011 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    maybe its the header() do you get any errors?
     
    bartolay13, Mar 18, 2011 IP
  3. Parallax

    Parallax Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    can u say what is the wrong with header()??
     
    Parallax, Mar 18, 2011 IP
  4. IAreOwn

    IAreOwn Active Member

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #4
    header() must be called before any output is sent, therefore you cannot use html tags, echo or print functions... and why is it even there you redirecting it to budget.php that makes your mysql query useless...
     
    IAreOwn, Mar 18, 2011 IP
  5. Parallax

    Parallax Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I really wanted to prevent submitting form values when refresh. Do you know another way to do it??
     
    Parallax, Mar 18, 2011 IP
  6. IAreOwn

    IAreOwn Active Member

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #6
    well, you can check if the submit button is clicked ie

    
    if(isset($_POST['submit']))
    {
        //do something here
    }
    
    PHP:
    
    <input type="submit" name="submit" />
    
    HTML:
     
    IAreOwn, Mar 18, 2011 IP