我是PHP新手,很抱歉缺乏正确的术语。我目前有一个php文件,显示我的数据库表在浏览器中,并提供了一个选项来编辑记录。但是,我不知道如何将编辑按钮连接到特定的记录,并将其带到第二个php页面进行编辑。
基本上我如何得到我点击编辑到我的第二个PHP文件的记录!
链接到代码是类似于如何我希望我的php页面的功能是http://www.shotdev.com/php/php-oracle/php-oracle-oci8-edit-update-data/
如有任何建议,我将不胜感激。下面是我的第一个PHP脚本代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?php
$dbuser = "scott";
$dbpassword = "tiger";
$db = "orabis";
$conn = oci_connect($dbuser,$dbpassword,$db);
$sql = "SELECT * FROM ATTENDEES";
$objParse = oci_parse ($conn, $sql);
oci_execute ($objParse,OCI_DEFAULT);
print '<table border="1">';
print '<tr>';
print '<th>FirstName</th>';
print '<th > LastName </th>';
print '<th > Email </th>';
print '<th > Address </th>';
print '<th > Company </th>';
print '<th > Title </th> ' ;
print '<th > City </th> ' ;
print '<th > State </th> ';
print '<th > Zip </th> ';
print '<th> Country </th>';
print '<th> Phone </th> ';
print '<th> Edit </th>';
print '</tr>';
while ($row = oci_fetch_array($objParse, OCI_RETURN_NULLS+OCI_ASSOC)) {
foreach ($row as $item) {
print '<td>'.($item !== null ? htmlentities($item, ENT_QUOTES) : ' ').'</td>';
}
print '<td><a href="modify_attendee2.php">Edit</a></td>';
print '</tr>';
}
print '</table>';
oci_close($conn);
?>
</body>
</html>
基本上需要一个ID作为主键来使用。如果你的表中已经有了这一列,那么你可以用两种不同的方式来构建你的特性:通过URL或通过FORM。
你需要一个像
这样的url<a href="edit_user.php?id=<?php echo $user_id; ?>">Edit</a>
然后在你的PHP文件(edit_user.php)中,你必须通过$_GET['user_id']
user_id
的值您将需要一个带有隐藏的输入的表单,其值将是用户id
<form action="edit_user.php">
<input type="hidden" name="user_id" value="<?php echo $user_id; ?>" />
<input type="submit" value="Edit" />
</form>
然后在您的PHP文件(edit_user.php)中,您必须通过$_POST['user_id']
user_id
值