dounai9592 2013-08-22 21:04 采纳率: 100%
浏览 28
已采纳

我的HTML表单值未被识别

I am not entirely sure but it looks like the values being posted by my forms e.g. Text1 for my first text box, are not being recognized by PHP.

Been wrestling with it all night, hopefully someone can help? Thanx.

<?php
$dbhost = 'localhost';
$dbuser = 'xeuser';
$dbpass = 'xepass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if(! $conn )
{
 die('Could not connect: ' . mysql_error());
}

$sql = 'INSERT INTO `amis_q1`.`crop1_8_9` (
`IDENTIFICATION` , `ADD` , `MARKET` , `DISTRICT` , `ENUMERATOR` , `Seller` , `Name_of_Unit` , `Number_of_Sellers` , `Average_Weight` , `Estimated_Weights` , `Type_of_Seller` , `Tramsport` , `Source` , `Remarks` , `CHECKED` , `BY` , `SUPERVISOR` , `OFFICE` , `DATE` , `INITIALS`
)
VALUES 
(   $_POST['Text1'],'$_POST[Text2]','$_POST[Text3]','$_POST[Text4]','$_POST[Text5]','$_POST[Text6]','$_POST[Text7]','$_POST[Text8]','$_POST[Text9]','$_POST[Text10]','$_POST[Text11]','$_POST[Text12]','$_POST[Text13]','$_POST[Text14]','$_POST[Text15]','$_POST[Text16]','$_POST[Text17]','$_POST[Text18]','$_POST[Text19]','$_POST[Text20]'
)';

mysql_select_db('amis_q1');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
 die('Could not enter data: ' . mysql_error());
}
print 'Inputted';
mysql_close($conn);
?>
  • 写回答

1条回答 默认 最新

  • doujiacai4986 2013-08-22 21:09
    关注

    Overarching problems: don't use mysql functions, and read about SQL injection, as your code (and the correct code below) are both extremely flawed from a security perspective.

    Other than that, the problem lies in your use of single quotes in $sql. Here's the correct way to do the last half of the variable:

    $sql = ') VALUES (' . $_POST['Text1'] . ', ' . $_POST['Text2'] . ')';
    

    ...this is the correct way to concatenate strings in PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢