检查发现post为空 应该怎么写
新手一个 刚自学了两天 过程中卡在不少地方过 这里是好不容易各种查各种找才搞出来的代码 现在卡在这里 求助啊
<?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
我在29行后面有个submit 用print_r($_POST)查看后是空的Array
提交后,$_POST 不会为空
但 $_POST['id'] 只用一个,并且是最后一个 $row['id']
这显然是不对的
提交后,$_POST 不会为空
但 $_POST['id'] 只用一个,并且是最后一个 $row['id']
这显然是不对的
版主大大
那如果我要给每一行附一个ID 用于之后的定位和删除应该怎么写呢
如果你想通过表单提交来实现删除,那么每行(tr)都应有一个表单(form)
而包围在外面的表单是不需要的
action=""
是提交到本页,可以不写
这样提交后,$_POST['id'] 才是待删除的 id
如果你想通过表单提交来实现删除,那么每行(tr)都应有一个表单(form)
而包围在外面的表单是不需要的
action=""
是提交到本页,可以不写
这样提交后,$_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>
我改成这样以后 echo的post依然是空啊 是哪出问题了?
你点击 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
中了hidden的招了
30行的value定错了
真是太感谢了 谢谢帮助!
你点击 delete 按钮了吗?
贴出浏览器中的 html
之前的错误只是之一啊
我数据库里写的是objid $row提的是id 这里错了
改了之后value得到值了 但是为啥post还是空啊
<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>
你是指
1Array
(
)
这个是空的吗?
这里要提交(点击 delete 按钮)后才会有值!
你点击 delete 按钮了吗?
贴出浏览器中的 html
之前的错误只是之一啊
我数据库里写的是objid $row提的是id 这里错了
改了之后value得到值了 但是为啥post还是空啊
<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>
额、、、 你while还是放form里面去吧。。。
你是指
1Array
(
)
这个是空的吗?
这里要提交(点击 delete 按钮)后才会有值!
点了delete之后发现post有值了
万分感谢!
你点击 delete 按钮了吗?
贴出浏览器中的 html
之前的错误只是之一啊
我数据库里写的是objid $row提的是id 这里错了
改了之后value得到值了 但是为啥post还是空啊
<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>
额、、、 你while还是放form里面去吧。。。
还是放里面才对吗?
你点击 delete 按钮了吗?
贴出浏览器中的 html
之前的错误只是之一啊
我数据库里写的是objid $row提的是id 这里错了
改了之后value得到值了 但是为啥post还是空啊
<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>
额、、、 你while还是放form里面去吧。。。
还是放里面才对吗?
这么多form 看着不别扭。。。
你可以改为使用复选框来让用户选中数据,复选框的名字为lst[],所有的复选框都叫这个,然后值为$row[id],然后通过一个按钮来提交数据到删除界面,php接收lst就能获取到所有的选中数据
而且提交到当前页面的话表单action可以为空

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.
