Have a look at my two different cases.
fun.php (Same in all case)
function pre_invoice($value) //earlier it was public function ---- (typo in the question)
{
//Code to insert query in database
}
Case 1:
form.php
<?php
require_once 'fun.php';
if(isset($_POST['submit'])){
pre_invoice(999);
}
?>
<table class="table table-striped table-hover table-bordered">
<thead class="text-center">
<tr>
<th>Service</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<form method="POST">
<tr>
<td></td>
<td>8</td>
</tr>
<tr>
<td></td>
<td>12</td>
</tr>
<tr>
<td></td>
<td>4</td>
</tr>
<tr>
<td></td>
<td>6</td>
</tr>
<input type="submit" name="submit" />
</form>
</tbody>
</table>
Now when I click submit button in form.php, the query is inserted in the database.
Case 2:
form.php
<table class="table table-striped table-hover table-bordered">
<thead class="text-center">
<tr>
<th>Service</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<form method="POST">
<tr>
<td></td>
<td>8</td>
</tr>
<tr>
<td></td>
<td>12</td>
</tr>
<tr>
<td></td>
<td>4</td>
</tr>
<tr>
<td></td>
<td>6</td>
</tr>
<input type="submit" name="submit" />
</form>
</tbody>
</table>
index.php
<?php
require_once 'fun.php';
if(isset($_POST['submit'])){
pre_invoice(999);
}
?>
<div id="form"></div>
<script>
$("#form").load('form.php');
</script>
Now when I click submit button in index.php, the query is not inserted in the database.
I have all libraries included in the index.php all HTML tags are proper, SQL query are proper.