help pls?? again?? i've been thinking what wrong with this,, when i hit record button, it will insert date, and total sales into a table, and that seems ok, but if there are no sales/ sold product, the total will be zero, but when i hit record button, it will not insert into the table. what's wrong?? huhu, everyting is fine if there is sold items, even if the total sales is 0, but if no sold items, and total is 0, it ain't inserting.. help meeee plsss......
Code: Select all
[u]view_sales.php[/u]
<?php
//include("header.php");
include("connection.php");
if (isset($_POST['fr_sub'])){
$date= $_POST['st_date'];
$total=0;
$query = "SELECT * FROM sales where date='$date'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) == 0)
{
echo "NO SALES-----";
}
else
{
echo "<table cellpadding='2'>";
echo "<h2>DATE: <b>".$date."</b></h2>";
echo "<tr><th>SALES ID</th><th>TIME</th><th>TOTAL PAYMENTS</th><th>CASH</th><th>CHANGE</th></tr>";
while($row = mysql_fetch_array($result))
{
$id=$row['sales_id'];
//echo "<form action ='view_sales4.php' method='get'>";
echo "<tr><td style='text-align:center'>";
echo $id;
//echo "<input type='hidden' name='sel_id' value=".$row['sales_id'].">";
echo "</td><td>";
echo $row['time'];
echo "</td><td style='text-align:center'>";
echo "P".$row['t_pay'];
echo "<input type='hidden' value='".$row['t_pay']."'>";
echo "</td><td style='text-align:center'>";
echo "P".$row['cash'];
echo "</td><td style='text-align:center'>";
echo "P".$row['change'];
//echo "</td><td>";
//echo "P".$row['price'];
//echo "</td><td>";
//echo $row['quantity'];
echo "</td><td>";
//echo '<a href="" rel="facebox">view sales</a>';
//echo "<input type='submit' name='view' value='view' >";?>
<a href="view_sales4.php?id=<?php echo $id; ?>" rel="facebox"><?php echo "view sale"; ?></a>
<?php echo "</td></tr>";echo "</form>";
$total += $row['t_pay'];
}
}
echo "</table>";
echo "<table>";
echo "<form action ='daily_sales.php' method='post'>";
//echo "<br />";
echo "<hr><tr>";
echo "<td>";
echo "<input type='hidden' name='date' value='".$date."'>";
echo "</td><td>";
echo "TOTAL SALE: <b>P".$total."</b>";
echo "</td><td>";
echo "<input type='hidden' name='total' value='".$total."'>";
echo "</td><td>";
echo "<input type='submit' name='record' value='RECORD' class='button'>";
echo "</td></tr>";
echo "</form>";
echo "</table>";
}
?>
[u]daily_sales.php[/u]
<?php
include("connection.php");
if(isset($_POST['record'])){
$total= $_POST['total'];
$date= $_POST['date'];
$query="SELECT * FROM daily_sales2 where '$date'=date";
$result=mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
if(mysql_num_rows($result)>0)
{
echo '<script>alert("GA CGE LANG TAG RECORD ANI!");location.href="index.php";</script>';
}
else
{
$query = "INSERT INTO daily_sales2 values (null,'$date','$total')";
$result = mysql_query($query) or die('error');
echo '<script>alert("MANIRA NATA!");location.href="index.php";</script>';
}
}
?>