<?php
$connec=mysql_connect("localhost","root","vertrigo") or die("不能连接数据库服务器: ".mysql_error());
mysql_select_db("data",$connec) or die ("不能选择数据库: ".mysql_error());
mysql_query("set names 'utf8'");
?>
<?php
if($_POST["id"] and $_POST["action"]=="del")
{
$sql="delete from class where id=$_POST[id]";
mysql_query($sql,$connec);
echo("<script type='text/javascript'> alert('删除成功!');location.href='test.php';</script>");
}
?>
<table width="900" border="1">
<form action="test.php" method="post" >
<tr>
<td>ID</td>
<td>classtitle</td>
<td>classurl</td>
<td>操作</td>
</tr>
<?php
$sql="select * from class order by ID desc";
$conn=mysql_query($sql,$connec);
while($rs=mysql_fetch_array($conn)){
?>
<tr>
<td><?php echo $rs['ID'] ?></td>
<td><?php echo $rs['stitle'] ?></td>
<td><?php echo $rs['surl'] ?></td>
<td><a href="?action=del&id=<?php echo $rs['ID']?>">删除</a></td>
</tr>
<?php
}
?></form></table>老是有错误。想请问下如何判断form提交的动作?还有,这样做不安全。如何做能有安全性?谢谢。
$connec=mysql_connect("localhost","root","vertrigo") or die("不能连接数据库服务器: ".mysql_error());
mysql_select_db("data",$connec) or die ("不能选择数据库: ".mysql_error());
mysql_query("set names 'utf8'");
?>
<?php
if($_POST["id"] and $_POST["action"]=="del")
{
$sql="delete from class where id=$_POST[id]";
mysql_query($sql,$connec);
echo("<script type='text/javascript'> alert('删除成功!');location.href='test.php';</script>");
}
?>
<table width="900" border="1">
<form action="test.php" method="post" >
<tr>
<td>ID</td>
<td>classtitle</td>
<td>classurl</td>
<td>操作</td>
</tr>
<?php
$sql="select * from class order by ID desc";
$conn=mysql_query($sql,$connec);
while($rs=mysql_fetch_array($conn)){
?>
<tr>
<td><?php echo $rs['ID'] ?></td>
<td><?php echo $rs['stitle'] ?></td>
<td><?php echo $rs['surl'] ?></td>
<td><a href="?action=del&id=<?php echo $rs['ID']?>">删除</a></td>
</tr>
<?php
}
?></form></table>老是有错误。想请问下如何判断form提交的动作?还有,这样做不安全。如何做能有安全性?谢谢。
你是从url上传值的。所以用get方式接受。把POST改为GET就可以了。
表单提交里面最常见的是提交<input>之类,像超连接<a>是用GET提交的。
把<form></form>去掉,然后用$_GET接收。