ホームページ >バックエンド開発 >PHPチュートリアル >確認したら、投稿が空でした。何を書けばよいでしょうか。
新手一个 刚自学了两天 过程中卡在不少地方过 这里是好不容易各种查各种找才搞出来的代码 现在卡在这里 求助啊
<?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)
e7fdee027fdcf4b22a7a622405defa8f">
a34de1251f0d9fe1e645927f19a896e8
b6c5a531a458a2e790c1fd6421739d1caadbc60520806b6b4b9bc2a6b694f5fcb90dd5946f0946207856a8a37f441edf
b6c5a531a458a2e790c1fd6421739d1c2f99b0403f9b5d9e791de3fc95af2c9eb90dd5946f0946207856a8a37f441edf
b6c5a531a458a2e790c1fd6421739d1c2f99dd7e40e8a7529bfe1c76b32a8bb4">3c0d181d97044f899afbc9cd39e3d1e3b90dd5946f0946207856a8a37f441edf
fd273fcf5bcad3dfdad3c41bd81ad3e5
f5a47148e367a6035fd7a2faa965022e
而包围在外面的表单是不需要的
action="1d293b64a40074eb318a175eee665efd"
是提交到本页,可以不写
这样提交后,$_POST['id'] 才是待删除的 id
如果你想通过表单提交来实现删除,那么每行(tr)都应有一个表单(form)
e7fdee027fdcf4b22a7a622405defa8f">
a34de1251f0d9fe1e645927f19a896e8
b6c5a531a458a2e790c1fd6421739d1caadbc60520806b6b4b9bc2a6b694f5fcb90dd5946f0946207856a8a37f441edf
b6c5a531a458a2e790c1fd6421739d1c2f99b0403f9b5d9e791de3fc95af2c9eb90dd5946f0946207856a8a37f441edf
b6c5a531a458a2e790c1fd6421739d1c2f99dd7e40e8a7529bfe1c76b32a8bb4">3c0d181d97044f899afbc9cd39e3d1e3b90dd5946f0946207856a8a37f441edf
fd273fcf5bcad3dfdad3c41bd81ad3e5
f5a47148e367a6035fd7a2faa965022e
而包围在外面的表单是不需要的
action="1d293b64a40074eb318a175eee665efd"
是提交到本页,可以不写
这样提交后,$_POST['id'] 才是待删除的 id
<?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>
你是指
dc6dce4a544fdca2df29d5ac0ea9906bad41ed44e726fad816716ff180603722点此添加信息5db79b134e9f6b82c0b36e0489ee08ed16b28748ea4df4d9c2150843fecfba68
1Array
(
)
这个是空的吗?
这里要提交(点击 delete 按钮)后才会有值!
你点击 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>
你是指
dc6dce4a544fdca2df29d5ac0ea9906bad41ed44e726fad816716ff180603722点此添加信息5db79b134e9f6b82c0b36e0489ee08ed16b28748ea4df4d9c2150843fecfba68
1Array
(
)
这个是空的吗?
这里要提交(点击 delete 按钮)后才会有值!
你点击 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可以为空