我通过单击 index.php 中带有 $("#btn").load("form.php") 的按钮加载表单,我想避免在提交后将页面重定向到操作文件并在表中添加一个项目这是在表格下。
我的演示在http://price.parag.website
<?php include "../connection.php" ?>
<h1>Add CPU</h1>
<form method="post" action="actions/cpu_action.php">
<label for="name">Name</label>
<input type="text" name="cpu_name" />
<label for="price">Price</label>
<input type="text" name="cpu_price" />
<input type="submit" value="Add" />
</form>
<?php
$sql = "SELECT id, cpu_name, cpu_price FROM cpu";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "<table>
<thead>
<tr>
<th>ID</th>
<th>CPU NAME</th>
<th>CPU PRICE</th>
</tr>
</thead>";
while($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['cpu_name'] . "</td>";
echo "<td>" . $row['cpu_price'] . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
jeck猫
一只名叫tom的猫