Home > Backend Development > PHP Tutorial > PHP POST无法获得数据

PHP POST无法获得数据

WBOY
Release: 2016-06-06 20:36:11
Original
862 people have browsed it

<code><?php if (!empty($_POST['work_content'])) {
                        include ("conn.php");
                        $sql = "insert into work (
                            work_id,
                            work_content,
                            work_time,
                            work_salary,
                            work_jiesuan,
                            work_location,
                            work_population,
                            work_enterprise_title,
                            release_time) 
                        values (
                            null,
                            '$_POST[work_content]',
                            '$_POST[work_time]',
                            '$_POST[work_location]',
                            '$_POST[work_salary]',
                            '$_POST[work_jiesuan]',
                            '$_POST[work_population]',
                            '$_POST[work_enterprise_title]',
                            now())";
                        mysql_query($sql);
                        mysql_set_charset("utf-8");

                    }
                    ?>
</code>
Copy after login
Copy after login

无法得到数据..另外一张页面同样的方法都可以

回复内容:

<code><?php if (!empty($_POST['work_content'])) {
                        include ("conn.php");
                        $sql = "insert into work (
                            work_id,
                            work_content,
                            work_time,
                            work_salary,
                            work_jiesuan,
                            work_location,
                            work_population,
                            work_enterprise_title,
                            release_time) 
                        values (
                            null,
                            '$_POST[work_content]',
                            '$_POST[work_time]',
                            '$_POST[work_location]',
                            '$_POST[work_salary]',
                            '$_POST[work_jiesuan]',
                            '$_POST[work_population]',
                            '$_POST[work_enterprise_title]',
                            now())";
                        mysql_query($sql);
                        mysql_set_charset("utf-8");

                    }
                    ?>
</code>
Copy after login
Copy after login

无法得到数据..另外一张页面同样的方法都可以

如果$_POST没有,看看php://input

直接打印出post数组看

<code>php</code><code>var_dump($_POST);
</code>
Copy after login

首先,你需要确认POST是否有数据,var_dump($_POST)试试。
其次需要确认sql没有问题,可以保存mysql_query的返回值,如果为false,就打印mysql_error试试。或者直接把$sql打印出来,在mysql客户端或者phpmyadmin里调试,看sql语句本身是否有问题。
需要注意的是,你直接在SQL里使用$_POST变量,这样有sql注入漏洞。建议用mysql_real_escape_string过滤。或者使用pdo bind。

这代码,看得真酸爽,wtf

接收一下mysql_query($sql)看下!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template