I'm working on a file called test.php
.
What I'm trying to do is, to insert a value into a table by clicking a submit button
I have two tables, tbl_1
and tbl_2
tbl_1
id | name | age
4 | john | 20
9 | tim | 25
8 | lea | 22
While tbl_2 have the same structure as tbl_1
, it is empty or without any value in it... the idea is that I want to have a button, after clicking on that button, it will insert the value of tbl_1
into tbl_2
based on the id
The question is, how do I fill in tbl_2
with the value of tbl_1
, through a click of a submit button?
I made a form, trying to bring the value from tbl_1
to tbl_2
, but to no avail...
<form action="test.php?id" method="post">
<input type="submit" class="btn btn-info btn-xs" name="submit" value="Copy"/>
</form>
<?php
if(isset($_POST['submit']))
{
$io = $_POST['io'];
$no_kes = $_POST['no_kes'];
$SQL = "INSERT INTO tbl_2(name, age) VALUES ( '".$name."', '".$age."')";
$result = mysql_query($SQL);
}
?>
Below is how my table looks like on the web.
Below is the code for the table I constructed.
<table class="table table-striped table-bordered">
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th></th>
</tr>
<?php
// Read
$per_page = 7;
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$start_from = ($page-1) * $per_page;
$sql = "select * from tbl_1";
$result = $mydb->query($sql);
while ($readrow = $result->fetch_array()) {
?>
<tr>
<td><?php echo $readrow['id']; ?></td>
<td><?php echo $readrow['name']; ?></td>
<td><?php echo $readrow['age']; ?></td>
<td>