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); ?>
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...
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: