Display data on same page in place of form

On my page I have top, left side,right side , footer containers. The top shows time date etc,the left side shows existing data from mysql, the footer has form which I output data to the right side.
I am making a new project ( making quotations), the left side would show in a table all quotes to a specific client.
I would input at the footer which will creates table on the right side.

Currently footer has one field ,name of customer which it correctly displays on the footer, which when accepted should show on the right side, clear the footer field and offer another form which after acceptance should clear the footer field and so on until the table is populated.

In my instance the 1st step ie name field display the name correctly but the name form does not clear but stays and adds the next form. How do I remove the name form, display name on right side and offer the next form?

 <?php 
setlocale(LC_MONETARY, 'en_IN');
date_default_timezone_set('Asia/Kolkata');
include "config.php"
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" type="text/css" />
    </head>

<body>
    <div class="container">
        <div class="parent">
        <?php include "head.php"; ?>

            <aside class="section leftSidebar">
            <?php include "left.php"; ?>
            </aside>

            <main class="section main">

<table class="tg">
<colgroup>
<col style="width: 120px"  />
<col style="width: 90px" />
<col style="width: 100px" />
<col style="width: 100px" />
<col style="width: 200px" />
<col style="width: 120px" />
<col style="width: 90px" />
</colgroup>
<thead>
Quotations
</thead>
<tbody>
<tr>
<td class="tg-h2xt">Contact</td>
<td class="tg-h2xt">Phone </td>
<td class="tg-h2xt">Quote No</td>
<td class="tg-h2xt">Date</td>
<td class="tg-h2xt">Details</td>
<td class="tg-h2xt">Amount</td>
<td class="tg-h2xt">Status</td>
</tr>
<tr>
<?php 

$sql = "SELECT * FROM quote";
$result_data=mysqli_query($conn, $sql);
                
while ($row_data = mysqli_fetch_assoc($result_data)) {
$q_no=$row_data['q_no'];
$q_date=$row_data['q_date'];
$customer=$row_data['q_code'];

echo "<td class='tg-0pky' ><form class='new' action= ''  method='POST'>
<input type='hidden'  name='id'  value=" .$row_data['q_id']. ">
<input type='submit'  class='cancelbtn1' name='delete' value='DELETE''></form></td>";

if(isset($_POST['id'])) {
$id=$_REQUEST['id'];
$query = "DELETE FROM quote WHERE q_id=$id" ;
$result = mysqli_query($conn,$query);
header("Location: quote.php");
}
echo "</td>";
echo "</tr>";

}    
echo "<td class='tg-zvt6'></td>";
echo "<td class='tg-zvt6'></td>";echo "<td class='tg-zvt6'></td>";echo "<td class='tg-zvt6'></td>";
echo "<td class='tg-zvt6'></td>";
echo "<td class='tg-zvt6'>" .number_format($sum,2). "</td>";
echo "<td class='tg-zvt6' colspan= '2'></td>";
if(isset($_POST['customer'])){
echo $cust_name;                    
}
?>
        </tbody>
        </table>
        </main>
            
            <aside class="section rightSidebar">
                <table class="tg">
<?php
if(isset($cust_name)){
echo "<tr>";
echo "<td class='tg-h2xt220'>" .$cust_name ."</td>";
}
?>
<td class="tg-h2xt80">No. </td>
<td class="tg-h2xt120">Item Code </td>
<td class="tg-h2xt220">Particulars</td>
<td class="tg-h2xt120">Rate</td>
<td class="tg-h2xt80">Qty </td>
<td class="tg-h2xt120">Amount</td>
</tr>        
<td colspan="6" style= text-align:left;>Sub - Head:</td> 
<tr>
<td class="tg-h2xt80">$1.
<td class="tg-h2xt120">$code
<td class="tg-h2xt220">$part
<td class="tg-h2xt80">$rate
<td class="tg-h2xt80">$qty
<td class="tg-h2xt120">$amount
</td>

</table>

<table>
<colgroup>
<col style="width: 300px"  />
<col style="width: 180px" />
<col style="width: 160px" />
<col style="width: 150px" />
<col style="width: 90px" />
<col style="width: 90px" />
</colgroup>

<td class="tg-n7df-cl">    
<td class="tg-n7df-cl">  
<td class="tg-n7df">Total
<td class="tg-n7df">10000000.00

<tr>
<td class="tg-n7df-cl">   
<td class="tg-n7df-cl"> 
<td class="tg-n7df"><label for="gst">GST%:</label><input type="text" placeholder='18%' name="gst" maxlength="6" size="4"/>

<td class="tg-n7df">10,000.00</td>  
</br>
</tr>

<td class="tg-n7df-cl">    
<td class="tg-n7df-cl">  
<td class="tg-n7df">Grand Total

<td class="tg-n7df">10000000.00

</tr>

</table>
<br>
Note: <input type="text"  name="note"  maxlength="60" size="60"/>    
<br>
Terms & Conditions:
<br>
By:<input type="text" name="salesman" placeholder='Name' />


</aside>
    </form>  

<footer class="section footer ">
<form name="quote" action=" " method="POST"> 
Customer:
<?php
  if(!isset($cust_name)){
$query="SELECT * FROM user_details WHERE u_type='Customer'";
$result = mysqli_query($conn, $query) or die ('Unable to execute'.mysqli_error($conn));
echo "<select name='customer'>";
echo "<option value='New'>New User</option>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value=".$row['u_id'].">".$row['org']."</option>";
}
echo "</select>";

  $cust_name=$_POST['customer'];
$query="SELECT * FROM user_details WHERE u_id='$cust_name'";
$result = mysqli_query($conn, $query) or die ('Unable to execute'.mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result)) {
        $cust_name=  $row['contact'] .',M/s.'. $row['org'] .','. $row['addr'] .','. $row['city'] .','. $row['pincode']; 
        
}
echo "<input class='blue'  type=submit name='next' value='Next >>' />";
echo "<input class='red' type=reset  name='Reset' value='Reset' />";
echo "</form>";
header("location: test.php");
}


  

   if(isset($cust_name)){ 
        echo "inserted";

 ?>      
        


Date:<input type="date" name="q_date"   />
Ref:<input type="test" name="q_ref"  maxlength="8" size="4"> 

Quotation No: <input type="text" id='customer' name="customer" />

Customer Ref:<input type="text" id='customer' name="customer" />
Customer Date:<input type="date" name="q_date"   />

<input class='blue'  type=submit name="next" value="Next >>" />
<input class='red' type=reset  name="Reset" value="Reset" />
<?php
}
?>
</form> 
</footer>
</div>
</div>
</body>
</html>

My suggestion is to try to keep your HTML and PHP separated as much as possible here’s a small example what I am talking about.

The output in the main part of the HTML (between ) :

<main id="content" class="mainStyle">
    <div class="cmsThreads">
        <?php
        $url = 'cms_forums.php';
        echo $pagination->page_links($url);
        foreach ($cms as $record) {
            echo '<article  class="display">' . "\n";
            echo "<h3>" . $record->heading . " on " . CMS::styleDate($record->date_added) . "</h3>\n";
            echo "<h4> Created by" . $record->author . "</h4>";
            echo "<p>" . CMS::intro($record->content, 200, $record->id) . "</p>\n";
           echo '</article>';
        }
        ?>
    </div>
</main>

The setting up the array (in your case I believe) or array of objects would go above the HTML -

<?php
require_once 'assets/config/config.php';
require_once "vendor/autoload.php";

use Miniature\CMS;
use Miniature\Pagination;

//$cms = CMS::fetch_all();
//echo "<pre>" . print_r($cms, 1) . "</pre>";
$current_page = $_GET['page'] ?? 1;
$per_page = 3;
$total_count = CMS::countAll();

$pagination = new Pagination($current_page, $per_page, $total_count);
$offset = $pagination->offset();

$cms = CMS::page($per_page, $offset);

?>
<!doctype html>
<html lang="en">
<head> 

You call to the database table can go there as well or in a function/class once you get more familiar wit PHP.

HTH - John

Your suggestion helped somewhat, however the issue I am facing is this:-
In the footer field i have a !isset(data) which allows me prompt for step 1 which is to display data of Step 1 on right side.
This is happening,
Once confirmed, the footer step 1 prompt should be replaced by step 2 prompt, The data should stay on right side, for this i am using isset(data), however once i confirm the data it should go to step 2, this is not happening. It is going back to step 1, and data from right side becomes blank.
code enclosed for your reference.

<?php 
session_start();
?>
<body>
<div class="container">
<div class="parent">
<?php include "head.php"; ?>

<aside class="section leftSidebar">
<?php include "left.php"; ?>
</aside>
        
<footer class="section footer ">
<?php

if(!isset($cust_name)){
$query="SELECT * FROM user_details WHERE u_type='Customer'";
$result = mysqli_query($conn, $query) or die ('Unable to execute'.mysqli_error($conn));

echo "<form  action=' ' method='post'>";
echo "<select name='customer' id='customer' onchange='this.form.submit()'>";
echo "<option value=''>New User</option>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value=".$row['u_id'].">".$row['org']."</option>";
}
echo "</select>";
$cust_name=$_POST['customer'];
$query="SELECT * FROM user_details WHERE u_id='$cust_name'";
$result = mysqli_query($conn, $query) or die ('Unable to execute'.mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result)) {
$cust_name=  $row['contact'] .',M/s.'.$row['org'] .','.$row['addr'] .','.$row['city'] .''.$row['pincode']; 
}
echo "<input class='blue'  type=submit name='next' value='Next >>' />";
echo "<input class='red' type=reset  name='Reset' value='Reset' />";
echo "</form>";
}

if(isset($_POST['accept'])) {
?>
<form  action=' ' method='post'>
Quotation No:
<input type="text" name="q_no"  required=" " />  
Quotation Date
<input type="date"  name="q_date"  required=" " /> 
Your Ref:
<input type="text" name="q_ref"  /> 
Your Date
<input type="date"  name="q_your"  />
Subject:
<input type="text"  name="q_subject" />
<input class='blue'  type=submit name='nextstep' value='Next >>' />
<input class='red' type=reset  name='Reset' value='Reset' />
</form>
<?php
$q_no=$_POST['q_no'];
$q_date=$_POST['q_date'];
$q_ref=$_POST['q_ref'];
$_q_your=$_POST['q_your'];
$q_subject=$_POST['q_subject'];
}
    

?>      
 </footer>
<aside class="section rightSidebar">
<table class="tg">
<?php

if(isset($cust_name)){
    echo $cust_name;
echo "<td class='tg-dvpl'><form class='new' action= ''  method='POST'>
<input type='submit'  class='blue-thin' name='accept' value='OK''>
<input type='submit'  class='green-thin' name='reset' value='Return''>
</form></td>";
}
if(isset($_POST['reset'])) {
    echo "Resetting......!";
}
if(isset($_POST['accept'])) {
    echo "<td class='tg-h2xt220'>" .$cust_name ."</td>";
    }

if(isset($_POST['nextstep'])) {
        echo "<td class='tg-h2xt220'>" .$cust_name ."</td>";
        echo "$q_no   .$q_date         .$q_ref         .$_q_your]";
        echo "$q_subject";
        }
    
?>
</div>
</div>
</body>
</html>

Web servers are stateless. They only receive the inputs ($_POST, $_GET, $_COOKIE, $_FILES, and $_SESSION) that are part of the current request. Any $_POST, $_GET, and $_FILES data only exists for the duration of the current request. You must do ‘something’ with this data if you want it to exist past the end of the current request.

For your process to keep track of where it is at, you would need to pass the relevant input(s) from one step to the next, then test and use the existence of specific inputs to control what the page does.

You should use a get method form for things that determine what will be displayed on a page, i.e. searching or selecting data. You should use a post method form when performing an action that will affect data (insert/update/delete.)

It appears that the first step in your process is to select from existing users (customers.) This should be a get method form. This will cause the user id to be submitted as a $_GET value. If you include any existing $_GET values in any form/link that you build, this value will be passed from one page request to the next, solving the most immediate problem.

You should also be consistent in the naming for any particular value throughout your code. The meaning of this first input is a user id. Yet, you are calling it both customer and cust_name. Pick one name and use that throughout the code.

Thanks for your advice, the data on page :slight_smile:,
and step 2 came up on footer along with step1, what I want is that when I move to step 2 step 1 should not appear on the footer!

Sponsor our Newsletter | Privacy Policy | Terms of Service