新手一个 刚自学了两天 过程中卡在不少地方过 这里是好不容易各种查各种找才搞出来的代码 现在卡在这里 求助啊
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn);?><html> <head> <title>Print test</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <br> 显示: <br> <form METHOD="POST" action="<?php echo $_SERVER['PHP_SELF'];?>"> <table id="table1"> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php while($row=mysql_fetch_array($result)) { ?> <tr> <td><?php echo $row['objname']?></td> <td><?php echo $row['objinfo']?></td> <td><input type="hidden" name="id" value="<?php echo $row['id']?>"><input type="submit" value="delete"/></td> </tr> <?php } ?> </table> <div><a href="http://localhost/test2/submit.php">点此添加信息</a></div> </form> <?php echo empty($_POST); /*if(!empty($_POST)){ $id = $_POST['id']; $sql = "delete from student where objid='$id'"; $query = mysql_query($sql); if($query){ echo "<script>alert('删除成功');history.back();</script>"; } }*/ ?> </body><?php mysql_close($myconn); ?></html>
没看到你有submit。
你可以加上print_r($_POST); 看看有没有post
没看到你有submit。
你可以加上print_r($_POST); 看看有没有post
提交后,$_POST 不会为空
但 $_POST['id'] 只用一个,并且是最后一个 $row['id']
这显然是不对的
提交后,$_POST 不会为空
但 $_POST['id'] 只用一个,并且是最后一个 $row['id']
这显然是不对的
如果你想通过表单提交来实现删除,那么每行(tr)都应有一个表单(form)
如果你想通过表单提交来实现删除,那么每行(tr)都应有一个表单(form)
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn);?><html> <head> <title>Print test</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <br> 显示: <br> <table id="table1"> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php while($row=mysql_fetch_array($result)) { ?> <form METHOD="POST"> <tr> <td><?php echo $row['objname']?></td> <td><?php echo $row['objinfo']?></td> <td><input type="hidden" name="id" value="<?php echo $row['id']?>"> <input type="submit" value="delete"/></td> </tr> </form> <?php } ?> </table> <div><a href="http://localhost/test2/submit.php">点此添加信息</a></div> <?php echo empty($_POST); print_r($_POST); /*if(!empty($_POST)){ $id = $_POST['id']; $sql = "delete from student where objid='$id'"; $query = mysql_query($sql); if($query){ echo "<script>alert('删除成功');history.back();</script>"; } }*/ ?> </body><?php mysql_close($myconn); ?></html>
你点击 delete 按钮了吗?
贴出浏览器中的 html
<html> <head> <title>Print test</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <br> 显示: <br> <table id="table1"> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <form METHOD="POST"> <tr> <td>obj1</td> <td>this is obj1</td> <td><input type="hidden" name="id" value="<br /><b>Notice</b>: Undefined index: id in <b>C:\xampp\htdocs\test2\test.php</b> on line <b>30</b><br />"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj2</td> <td>this is obj2</td> <td><input type="hidden" name="id" value="<br /><b>Notice</b>: Undefined index: id in <b>C:\xampp\htdocs\test2\test.php</b> on line <b>30</b><br />"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj3</td> <td>this is obj3</td> <td><input type="hidden" name="id" value="<br /><b>Notice</b>: Undefined index: id in <b>C:\xampp\htdocs\test2\test.php</b> on line <b>30</b><br />"> <input type="submit" value="delete"/></td> </tr> </form> </table> <div><a href="http://localhost/test2/submit.php">点此添加信息</a></div> 1Array() </body></html>
你点击 delete 按钮了吗?
贴出浏览器中的 html
你点击 delete 按钮了吗?
贴出浏览器中的 html
你点击 delete 按钮了吗?
贴出浏览器中的 html
<html> <head> <title>Print test</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <br> 显示: <br> <table id="table1"> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <form METHOD="POST"> <tr> <td>obj1</td> <td>this is obj1</td> <td><input type="hidden" name="id" value="1"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj2</td> <td>this is obj2</td> <td><input type="hidden" name="id" value="2"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj3</td> <td>this is obj3</td> <td><input type="hidden" name="id" value="3"> <input type="submit" value="delete"/></td> </tr> </form> </table> <div><a href="http://localhost/test2/submit.php">点此添加信息</a></div> 1Array() </body></html>
你是指
你点击 delete 按钮了吗?
贴出浏览器中的 html
<html> <head> <title>Print test</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <br> 显示: <br> <table id="table1"> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <form METHOD="POST"> <tr> <td>obj1</td> <td>this is obj1</td> <td><input type="hidden" name="id" value="1"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj2</td> <td>this is obj2</td> <td><input type="hidden" name="id" value="2"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj3</td> <td>this is obj3</td> <td><input type="hidden" name="id" value="3"> <input type="submit" value="delete"/></td> </tr> </form> </table> <div><a href="http://localhost/test2/submit.php">点此添加信息</a></div> 1Array() </body></html>
你是指
你点击 delete 按钮了吗?
贴出浏览器中的 html
<html> <head> <title>Print test</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <br> 显示: <br> <table id="table1"> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <form METHOD="POST"> <tr> <td>obj1</td> <td>this is obj1</td> <td><input type="hidden" name="id" value="1"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj2</td> <td>this is obj2</td> <td><input type="hidden" name="id" value="2"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj3</td> <td>this is obj3</td> <td><input type="hidden" name="id" value="3"> <input type="submit" value="delete"/></td> </tr> </form> </table> <div><a href="http://localhost/test2/submit.php">点此添加信息</a></div> 1Array() </body></html>
你点击 delete 按钮了吗?
贴出浏览器中的 html
<html> <head> <title>Print test</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <br> 显示: <br> <table id="table1"> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <form METHOD="POST"> <tr> <td>obj1</td> <td>this is obj1</td> <td><input type="hidden" name="id" value="1"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj2</td> <td>this is obj2</td> <td><input type="hidden" name="id" value="2"> <input type="submit" value="delete"/></td> </tr> </form> <form METHOD="POST"> <tr> <td>obj3</td> <td>this is obj3</td> <td><input type="hidden" name="id" value="3"> <input type="submit" value="delete"/></td> </tr> </form> </table> <div><a href="http://localhost/test2/submit.php">点此添加信息</a></div> 1Array() </body></html>
你可以改为使用复选框来让用户选中数据,复选框的名字为lst[],所有的复选框都叫这个,然后值为$row[id],然后通过一个按钮来提交数据到删除界面,php接收lst就能获取到所有的选中数据
而且提交到当前页面的话表单action可以为空