我试过每个版本的代码,但它不工作。我有一个调用Post-PHP页面的HTML表单来在数据库中插入几个字段。只有带有直接文本的字段才会添加,但通过参数$_POST
发送的任何内容都是空的 - 无论我改变什么内容都无法通过。PHP MySQL通过html表格插入查询,参数不通过
HTML表单:
<html>
<table><form method="post" action="input.php">
<tr><td>Post Title</td>
<td><input type="text" name="fdt_post_title" size="20"></td></tr>
<tr><td>Post URL</td><td><input type="text" name="fdt_post_url" size="40"></td></tr>
<tr><td>Post Description</td><td><input type="text" name="fdt_post_desc" size="40"></td></tr>
<tr><td>Post Title for FB</td><td><input type="text" name="fdt_post_title_fb" size="40"></td></tr>
<tr><td>Image URL</td><td><input type="text" name="fdt_image_url_fb" size="40"></td></tr>
<tr><td></td><td align="right"><input type="submit" name="submit" value="Submit"></td></tr>
</form></table>
</html>
input.php页:
<?php
$dt_post_title = mysql_real_escape_string($_POST['$fdt_post_title']);
$dt_post_url = mysql_real_escape_string($_POST['$fdt_post_url']);
$dt_post_desc = mysql_real_escape_string($_POST['$fdt_post_desc']);
$dt_post_title_fb = mysql_real_escape_string($_POST['$fdt_post_title_fb']);
$dt_image_url_fb = mysql_real_escape_string($_POST['$fdt_image_url_fb']);
$link = mysql_connect("localhost","root","");//database connection
mysql_select_db("bighorn1_autoshare", $link);
$now = date();
//inserting data order
$order = "INSERT INTO topics
(id, title, url, description, facebook_post, facebook_image, facebook_pubstatus, date_published)
VALUES
(DEFAULT, '$dt_post_title', '$dt_post_url', '$dt_post_desc', '$dt_post_title_fb', '$dt_image_url_fb', '0', '$now')";
//declare in the order variable
$result = mysql_query($order, $link); //order executes
if($result){
echo("<br>Input data is succeed<br>");
} else {
echo("<br>Input data is fail<br>");
}
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
在该表中,现场id
是Primary, Not Null, Auto Increment
。所有我得到的是id
数量递增以达到新的行下单,facebook_pubstatus
为0
和date_published as
0000-00-00 00:00:00`
--------------------------------------------------------------------------------------------------------------------------------
id | title | url | description | facebook_post | facebook_image | facebook_pubstatus | date_published |
--------------------------------------------------------------------------------------------------------------------------------
1 | | | | | | 0 | 0000-00-00 00:00:00 |
--------------------------------------------------------------------------------------------------------------------------------
2 | | | | | | 0 | 0000-00-00 00:00:00 |
--------------------------------------------------------------------------------------------------------------------------------
等等....
如果我更改为(DEFAULT, '$dt_post_title', '$dt_post_url' .... ") like (DEFAULT, 'test String 1',......)
中的直接字符串,则此文本没有问题经过。
任何神奇可感,谢谢。
还强调这部分太多了,我的大脑没有搞清楚现在的日期是什么,为什么所有的零都是零。
谢谢
请,或不使用'mysql_ *'功能(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions- in-php),它们不再被维护,并且[已正式弃用](https://wiki.php.net/rfc/mysql_deprecation)。学习[准备的语句](http://en.wikipedia.org/wiki/Prepared_statement),并使用[PDO](http://us1.php.net/pdo)或[MySQLi](http:// us1.php.net/mysqli)。 [本文](http://php.net/manual/en/mysqlinfo.api.choosing.php)将帮助你决定。 – 2014-11-06 20:10:39
在打开'<?php tag error_reporting(E_ALL)'后立即向文件顶部添加错误报告; ini_set('display_errors',1);' – 2014-11-06 20:12:07
谢谢@JayBlanchard我一定会考虑它。 – user2350586 2014-11-06 20:13:42