good day, i'm new to programming but i'm eager to learn, i have a problem,
after i submit the number of quantity, the product will add, but then when i search again for another item, the page refresh.. i wanted to output all of the items in sales table so that i could get the grand total.. do i need condition statements for continuos printing in the sales table after selecting an item? do i need to separate the sales page,but i want it on a same page? do i need to store it in an array and output?,, please help me,where to start next, or my code sucks,do it all over again??? :(

<title> SALES </title>
<body>
<form action="index.php" method="post">
ENTER ID: <input type="text" name="item" />
<input type="submit" name="submit" value="submit"/>
<input type="submit" name="refresh" value="refresh" meta http-equiv="refresh" />
</form> 



<?php
include("connection.php");

if(isset($_POST['submit'])){
$sel_item = $_POST['item'];
$query  = "SELECT * FROM items where {$sel_item} = id";
$result = mysql_query($query) or die();
echo "<table>";
echo "<tr><th>ID</th> <th>ITEM NAME</th> <th>DESCRIPTION</th> <th>SIZE</th> <th>COLOR</th> <th style='text-align:right'>PRICE</th> <th style='text-align:right'>QUANTITY</th></tr>";

while($row = mysql_fetch_array($result)) {
	
	echo"<tr><td>";
	echo $row['id'];
	echo"</td><td>";
	echo $row['item_name'];
	echo"</td><td>";
	echo $row['description'];
	echo"</td><td>";
	echo $row['size'];
	echo"</td><td>";
	echo $row['color'];
	echo"</td><td style='text-align:right'>";
	echo "P".$row['price'];
	echo"</td><td style='text-align:right'>";
	echo $row['quantity'];
	echo "</td><td>";
		
}
echo "</table>";
}
?>



<br/><br/>
<h1>SALES</h1>
<form action="index.php" method="post">
<table width="400">
<tr>
<td> ID: <strong><?php echo $sel_item ?></td>
</tr>
<tr>
<td> QUANTITY: </td><td><input type="text" name="quantity"/></td>
<td> <input type="submit" name="add" value="add" ></td>
</tr>

<?php
include("connection.php");
$total=0;
if(isset($_POST['add'])){
$selc_item = $_POST['selc_item'];
$item_quantity = $_POST['quantity'];
$query  = "SELECT * FROM items where {$item_quantity} <= quantity ";
$result = mysql_query($query) or die();
echo"<table>";
echo"<tr>";
echo"<th>ID</th><th>ITEM NAME</th><th>QUANTITY</th><th>PRICE</th><th>TOTAL PRICE</th><th></th></tr>";

while($row = mysql_fetch_array($result)){
		
		$item_name = $row[1];
		$item_price = $row[5];
		$t_item_price = $row[5] * $item_quantity;
		
		
		
}

		echo"<tr>";
		echo"<td>{$selc_item}</td>";
		echo"<td>{$item_name}</td>";
		echo"<td>{$item_quantity}</td>";
		echo"<td>{$item_price}</td>";
		echo"<td>{$t_item_price}</td>";
		echo"</tr><br />";
		echo"</table>";
		
}
?>
</form>
</html>

this is the page that i created.. :)

I'm not sure what you want to achieve, but if you want the page to remember things, you need to start a session. This will remain current until you then logout. Try putting this at very first line on the page.

<?php
session_start();
?>

hi, do i need sessions? i want to continuously add items to the sales table, like in the picture, i've added a single item, but every time i search again for an item, the page reset, at the same time my sales table which is below, items will be gone, do i need another condition to continue adding items below even if i search for another item?? huhuhu,,, :(

Try below code.
Here i have used session to remember previous items.

<? session_start();?>
<title> SALES </title>
<body>
<form action="index.php" method="post">
ENTER ID: <input type="text" name="item" />
<input type="submit" name="submit" value="submit"/>
<input type="submit" name="refresh" value="refresh" meta http-equiv="refresh" />
</form> 



<?php
include("connection.php");

if(isset($_POST['submit'])){
$sel_item = $_POST['item'];
$query  = "SELECT * FROM items where {$sel_item} = id";
$result = mysql_query($query) or die();
echo "<table>";
echo "<tr><th>ID</th> <th>ITEM NAME</th> <th>DESCRIPTION</th> <th>SIZE</th> <th>COLOR</th> <th style='text-align:right'>PRICE</th> <th style='text-align:right'>QUANTITY</th></tr>";

while($row = mysql_fetch_array($result)) {
	
	echo"<tr><td>";
	echo $row['id'];
	echo"</td><td>";
	echo $row['item_name'];
	echo"</td><td>";
	echo $row['description'];
	echo"</td><td>";
	echo $row['size'];
	echo"</td><td>";
	echo $row['color'];
	echo"</td><td style='text-align:right'>";
	echo "P".$row['price'];
	echo"</td><td style='text-align:right'>";
	echo $row['quantity'];
	echo "</td><td>";
		
}
echo "</table>";
}
?>



<br/><br/>
<h1>SALES</h1>
<form action="index.php" method="post">
<table width="400">
<tr>
<td> ID: <strong><?php echo $sel_item ?></td>
</tr>
<tr>
<td> QUANTITY: </td><td><input type="text" name="quantity"/></td>
<td> <input type="submit" name="add" value="add" ></td>
</tr>

<?php
//include("connection.php");
$total=0;
if(isset($_POST['add'])){
$selc_item = $_POST['selc_item'];
$item_quantity = $_POST['quantity'];
$query  = "SELECT * FROM items where {$item_quantity} <= quantity ";
$result = mysql_query($query) or die();
$row = mysql_fetch_array($result);
$item_name = $row[1];
$item_price = $row[5];
$t_item_price = $row[5] * $item_quantity;

$cnt = count($_SESSION['master']);
$cnt++;
$_SESSION['master'][$cnt]['selc_item'] = $selc_item;
$_SESSION['master'][$cnt]['item_name'] = $item_name;
$_SESSION['master'][$cnt]['item_quantity'] = $item_quantity;
$_SESSION['master'][$cnt]['item_price'] = $item_price;
$_SESSION['master'][$cnt]['t_item_price'] = $t_item_price;		
}

if(count($_SESSION['master']) > 0 )
{
	echo"<table>";
	echo"<tr>";
	echo"<th>ID</th><th>ITEM NAME</th><th>QUANTITY</th><th>PRICE</th><th>TOTAL PRICE</th><th></th></tr>";
		
		for($i=0;$i<count($_SESSION['master']);$i++)	
		{
			echo"<tr>";
			echo"<td>".$_SESSION['master'][$i]['selc_item']."</td>";
			echo"<td>".$_SESSION['master'][$i]['item_name']."</td>";
			echo"<td>".$_SESSION['master'][$i]['item_quantity']."</td>";
			echo"<td>".$_SESSION['master'][$i]['item_price']."</td>";
			echo"<td>".$_SESSION['master'][$i]['t_item_price']."</td>";
			echo"</tr><br />";
		}
		
	echo"</table>";
}
?>
</form>
</html>

Your code for starting the session is nor correct. Do this.

<?php
session_start();
?>

good day master, i tried the code u've given me, but it wont print anything in the sales table, huhu, is session needed for my concept??is my query ok? the flow of my script compare to the flow of the picture?? huhu, i'm trying to output a data row in the main table which is the sale, but then when i search for an item again, the data in the table is gone, huhuhuhu, huhuhu thank you so much master, ill review my sessions topic,,,

woooooohhhhhhh im so soryyy,, its working... i need to review my sessions topic,, thnks so muchh master,,, can i aask agen?? HUHUHUHU, all the output in the main table, is it stored in an array,??? next, i will submit this results to another table, update the quantity value, query the items and date,,, am i right? i'll post my next code,,,,,,,,,,,,,,,,,,, thankkkkkkkkk youuuuuuuuuuu soooooooooo mucccccchhhhhhhh!

NEED HELP AGAIN.. huhuhuhuhuhu i have this error, a screenie is attached.. somebody??:'(

[U]index.php[/U]

<?php
session_start();

if (!isset($_SESSION['user_id'])){
	header('location: login.php');
}
?>
<html>

<title> WEEEE </title>

<h1><b>SALES AND INVENTORY</b></h1>
	<form action='sales.php' method='post'>
	<input type='submit' name='new_sale' value='new_sale'/>
	</form>
</html>	

[U]login.php[/U]

<?php
include("connection.php");
;
if (isset($_POST['login'])) {
		$username = trim(($_POST['user']));
		$password = trim(($_POST['pass']));
		//$hashed_password = sha1($password);
		$query = "SELECT * FROM users where username='$username' and password='$password'";
		$result = mysql_query($query) or die();
		
		if (mysql_num_rows($result) > 0) 
			{
				// username/password authenticated
				// and only 1 match
				session_start();
				$user = mysql_fetch_row($result);
				$_SESSION['user_id'] = $user['id'];
				$_SESSION['username'] = $user['username'];
				header('location: login.php');
			}
		else 
			{
				// username/password combo was not found in the database
				echo "invalid user!";
			}		
}
?>


<html>
<br /><br /><br />
<form action="login.php" method="post">
<table align="center" >
<tr>
<td>USERNAME:</td>
<td><input type="text" name="user"   maxlength="30"></td>
</tr><tr>
<td>PASSWORD</td>
<td><input type="password" name="pass"   maxlength="30"></td>
</tr><tr>

<td><input type="submit" name="login" value="login"></td>
</tr>

</tr>
</form>
</html>

session_start must be first line of your code.
<?php session_start();
There should be no blank space or line breaks before this function start.

can you help me point to where i went wrong master?? i've change the position of the session, still no luck, do u have an example of those line breaks/white spaces?? huhuhu sorry for this newbie question..huhu

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...... :( :( :(

<span style="text-decoration: underline">view_sales.php</span>

<?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>";

       
}
?>

<span style="text-decoration: underline">daily_sales.php</span>

<?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>';
                               
                                                       
                        }
}

?>
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.