【发布时间】:2014-08-08 20:10:32
【问题描述】:
我有一个表格:
<table border="1">
<tr>
<td align="center">Form Input Employees Data</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="input.php">
<input type="hidden" name="id" value="1234">
<tr>
<td>Product Name</td>
<td><input type="text" name="name" size="20">
</td>
</tr>
<tr>
<td>Brand</td>
<td><input type="text" name="brand" size="40">
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit" value="Sent"></td>
</tr>
</form>
</table>
而我的 input.php 是:
<?
//the example of inserting data with variable from HTML form
//input.php
mysql_connect("localhost","xxx","xxx");//database connection
mysql_select_db("xxxx_xxx");
//inserting data order
$order = "INSERT INTO wp_userdata
(id, product_name, product_brand)
VALUES
('$_POST[id]',
'$_POST[name]',
'$_POST[brand]')";
//declare in the order variable
$result = mysql_query($order); //order executes
if($result){
echo("<br>Input data is succeed");
} else{
echo("<br>Input data is fail");
}
?>
当我点击发送按钮时,新行被添加到数据库表中,但只记录product_name 和product_brand。隐藏的输入“id”值没有进入表...
如何让它记录所有 3 个值:id、product_name 和 product_brand?
【问题讨论】:
-
print_r($_POST)在您的input.php文件中并在此处发布结果。 -
Array ([id] => comparebest [name] => Test14 [brand] => dfg [submit] => Sent )
-
您的
id是此处的文字。id的数据库中可能有int数据类型 -
现在一切正常,不知道这时候出了什么问题
-
不要相信用户提交的输入!
标签: php html mysql database forms