Delete by button

Hi i want to delete info by click a button. When i push the buutton it just refresh the page.

	require_once("connect.php");
	if (isset($_POST['buton']))
	{	$tablenumber=$_POST['number'];
		if (isset($_POST['Finish']))	
		{	$sql3="	DELETE FROM orders WHERE table_number=$tablenumber;";
			$quer3=mysqli_query($conn,$sql3)or die ('error sql');
		}
		$sql="SELECT orders.code,menu.name,orders.count,menu.price, orders.count*menu.price as Total 
		FROM orders,menu WHERE table_number=$tablenumber and orders.code=menu.code";	
		$quer=mysqli_query($conn,$sql)or die ('error sql');
		$num=mysqli_num_rows($quer);

		$sql2="SELECT  SUM(orders.count*menu.price) as TotalPrice 
		FROM orders,menu WHERE table_number=$tablenumber and orders.code=menu.code";	
		$quer2=mysqli_query($conn,$sql2)or die ('error sql2');		
	}
?>
<html>
<form action="login.php" method="post">
<span style="display:flex; justify-content:flex-end; width:100%; padding:0;">
    <input type="submit" value="Exit"/>
</form>
</span>
		<style>
			body {background-color: #87CEEB;}
		</style>
    <head>
        <title>Factura</title>
        <!---<meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="dff.css"/>  !--->
    </head>
    <body>  
        <form id="frmFactura" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
				
           <div id="cabeceraFactura">
				<br>
				<SELECT NAME="number" size="1">
					<option value="---">---</option>
					<?php
						for($i=1;$i<=20;$i++)
						{ echo "<option value=".$i.">".$i."</option>";}
					?>
				</SELECT>				
				<input type='submit' name='buton' value="NEXT"/>	
            </div>
			<br>
            <table id ="detalle" border="2" width="3" cellspacing="2" cellpadding="1">
				<thead>
                    <tr>
					 <th>Name</th>
                        <th>Count</th>
                        <th>Unit price</th>
                        <th>Total</th>
                    </tr>
                </thead>
                <tbody>
				<?php
					if(isset($_POST['buton']))
					{	 while ($resul=mysqli_fetch_array($quer) )	
						{	echo '
					<tr>
                        <td><input class="descrip" type="text" name="naimenovanie" value="'.$resul["name"].'" disabled=""/></td>
                        <td><input class="cant" type="text" name="kolichestvo"  value="'.$resul["count"].'" disabled=""/></td>
                        <td><input class="vunit"type="text"  name="cena" value="'.$resul["price"].'" disabled=""/></td>
                        <td><input class="totPro" type="text"  name="obstho" value="'.$resul["Total"].'" disabled=""/></td>		
                    </tr>
						';
						}
					}		
				?>	
                </tbody>
            </table> 
			<br>
			<div class="Resultados">
				<table border="2" width="3" cellspacing="2" cellpadding="1">                  
					<tr>
						<td><label id="lbl">TotalPrice</label></td>
						<?php
							if(isset($_POST['buton'])) $resul2=mysqli_fetch_array($quer2);
						?>
						<td><input class="totPro" type ="text" value="<?php if(isset($_POST['buton'])) 
						 echo $resul2['TotalPrice'];?>"  disabled=""/> </td>
					 
					</tr>   
				</table>
				<br>
				<button onclick="window.print()" width="200">Print </button>	
				<input type="submit"  name= "Finish" value = "Finish">
			</div>
        	</form>

This is the code so when I push the button Finish in theory should delete all orders on the table in DB. I even try with checkbox the same result.

For debugging purposes, add the following line of code before the start of your post method form processing code so that you can see what data is being submitted on each request -

echo '<pre>'; print_r($_POST); echo '</pre>';

image
the first one is when i push button NEXT

image
the second one is Finish

Displaying the submitted data was for YOU to look at to see what is being submitted so that you can devise code that will work.

Sponsor our Newsletter | Privacy Policy | Terms of Service