dq_1984 2014-11-06 20:06
浏览 55
已采纳

PHP MySQL通过html表单插入查询,参数不通过

I tried every version of code but it is not working. I have an HTML form calling Post- PHP page to insert few fields in database. Only fields with direct text are adding, but anything coming via $_POST parameters are empty - nothing getting through no matter what I change.

HTML FORM:

<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 page:

<?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) . "
";
?>

In the table, Field id is Primary, Not Null, Auto Increment. All I am getting is id number incremented to next one in reach new row, facebook_pubstatus as 0 and date_published as0000-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 |
--------------------------------------------------------------------------------------------------------------------------------

and so on....

If I change to direct string in (DEFAULT, '$dt_post_title', '$dt_post_url' .... ") like (DEFAULT, 'test String 1',...... ) then this text has no issues going through.

Any magic appreciable, thanks.

Also stressing on this part too much, my brain not figuring out whats with the date now, why all zeros.

Thanks

  • 写回答

2条回答 默认 最新

  • dongxie2756 2014-11-06 20:11
    关注

    You have an extra '$' sign in your variables. Change to this:

    $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']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch