각 행의 테이블에서 링크를 삭제하고 있습니다. 해당 링크를 클릭하면 해당 ID를 사용하여 해당 행을 삭제하는 페이지로 ID를 전달합니다. 내가 보여주는 밖으로에만 delete_row.php을 보여줄 수 = 내 URL의 내 마지막 부분이 delete_row.php처럼 보인다? ID? ID = 5PHP URL 링크 재 작성
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function redirect(URL)
{
document.location="delete_row.php";
return false;
}
</script>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM users");
?>
<table border="1">
<th>Name</th>
<th>Age</th>
<th> </th>
<?php
while($row = mysql_fetch_array($result))
{?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['age'];?></td>
<td><a href="javascript:" onclick="return redirect('delete_row.php?id=<?php echo $row['id']; ?>');">Delete</a></td>
</tr>
<?php } ?>
</table>
<?php
mysql_close($con);
?>
</body>
</html>
이 파일 이름 delete_row와 PHP 부분입니다. PHP
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
if(isset($_REQUEST['id']))
$id = $_REQUEST['id'];
mysql_query("DELETE FROM users WHERE id='$id'");
mysql_close($con);
?>
내가 공지 사항입니다 무엇입니까 오류 : 정의되지 않은 변수 : C에서 ID :
[부작용이있는 요청에는 GET을 사용하지 마십시오] (http://tools.ietf.org/html/rfc2616#section-9.1.1). – Gumbo
대신 GET을 시도해 볼 수 있습니다 – jimy
실제 질문은 "왜 이걸하고 싶니?"라고 가정합니다. – briantyler