从表1中的id,如何在表1中使用相同的id将数据添加到表2中

时间:2016-03-10 22:10:48

标签: php mysql

我为项目留出时间和时间,但我陷入了这个

如何将其显示为php?

名称|中间名|姓氏| [DTR](DTR是指向dtr.php的其他页面的链接)

然后进入[DTR]链接,它将显示

时间在| TIME_OUT
[添加时间]([添加时间]是add_time.php的链接所以基本上时间和时间是dtr.php中的循环

问题是我可以添加time_in和time_out也在我提交后我不能直接转到dtr.php?= $ id

到目前为止,这是我尝试过的一个

view.php

<?php
include 'dbconfig.php';
$sql = "SELECT * FROM info";
$result = mysql_query($sql);
?>
"enter code here"
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><center>".$row['firstname']."</center></td>";
echo "<td><center>".$row['middlename']."</center></td>";
echo "<td><center>".$row['lastname']."</center></td>";
echo "<td><a href= \"dtr.php?id=".$row['id']." \"> DTR";
echo "</tr>";
}

dtr.php

<?php
include 'dbconfig.php';

$time_id = $_GET['id'];
$sql = "SELECT * FROM time WHERE id = '$time_id'";
$result = mysql_query($sql);
?>
"enter code here"
<?php
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><center>".$row['time_in']."</center></td>";
echo "<td><center>".$row['time_out']."</center></td>";
echo "<td><a href= \"add_time.php?id=".$row['id']." \"> edit </a></td>";
echo "</tr>";
}
?>

add_time.php

<?php
include 'dbconfig.php';
$time_id = $_GET['id'];
$sql = "SELECT * FROM time WHERE id = '$time_id'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>

<form action="insert_time.php" method="POST">
time in: <input type="text" name="time_in"/><br/>
time out: <input type="text" name="time_out"/><br/>
</form>

<?php echo '<td><form action="dtr.php?id=' . $row['id'] . '"><input type="submit" name="save" value="Save" /></form></td>'; ?>

insert_time.php

<?php
include 'dbconfig.php';

$time_id = $_GET['id'];
$sql = "SELECT * FROM time WHERE id = '$time_id'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

$time_in = $_POST['time_in'];
$time_out = $_POST['time_out'];

$sql = "INSERT INTO time (time_in, time_out) VALUES ('$time_in','$time_out')
$query = mysql_query($sql);

mysql_close();

Header("Location: dtr.php?id=".$time_id);
?>

这是我的信息表

| id | firstname | middlename | lastname |

时间表

| time_id | id | time_in | time_out |

0 个答案:

没有答案