-1

使用以下代码(html / SQL),代码无法执行。我非常擅长 MySQL,但这是我的代码:

请求的订单

输入项目和数量

<input type="text" name="email" size="40"><br>

<input type="text" name="item_one" size="40"><br>

<input type="text" name="item_two" size="40"><br>

<input type="text" name="item_three" size="40"><br>

<input type="text" name="item_four" size="40"><br>

<input type="text" name="item_five" size="40"><br>

<input type="text" name="item_six" size="40"><br>

<input type="text" name="item_seven" size="40"><br>

<input type="text" name="item_eight" size="40"><br>

<input type="text" name="item_nine" size="40"><br>

<input type="text" name="item_ten" size="40"><br>

<input type="text" name="item_eleven" size="40"><br>

<input type="text" name="item_twelve" size="40"><br>

<input type="text" name="item_thirteen" size="40"><br>

<input type="text" name="item_fourteen" size="40"><br>

<input type="text" name="item_fifthteen" size="40"><br>

<input type="submit" name="submit" value="Sent">

这是function.php

<?php
//the example of inserting data with variable from HTML form
//function.php
mysql_connect("localhost","root","");//database connection
mysql_select_db("order_db");

//inserting data order
$order = "INSERT INTO requested_inventory
            (name, email, item_one, item_two, item_three, item_four, item_five, item_six, item_seven, item_eight, item_nine, item_ten, item_eleven, item_twelve, item_thirteen, item_fourteen, item_fifthteen)
            VALUES
            ('name',
            'email', 'item_one', 'item_two', 'item_three', 'item_four', 'item_five', 'item_six', 'item_seven', 'item_eight', 'item_eight', 'item_nine', 'item_ten', 'item_eleven', 'item_twelve', 'item_thirteen', 'item_fourteen', 'item_fifthteen')";

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

我不确定我哪里出错了。任何有关示例的帮助将不胜感激。

注意:这是在 localhost 机器上,所以不需要完全安全,这就是我使用 root 没有密码的原因。

4

4 回答 4

2

你有额外的领域item_eight2 次。试试喜欢

"INSERT INTO requested_inventory
(name, email, item_one, item_two, item_three, item_four, item_five, item_six, item_seven, item_eight, item_nine, item_ten, item_eleven, item_twelve, item_thirteen, item_fourteen, item_fifthteen)
VALUES
('name','email', 'item_one', 'item_two', 'item_three', 'item_four', 'item_five', 'item_six', 'item_seven', 'item_eight', 'item_nine', 'item_ten', 'item_eleven', 'item_twelve', 'item_thirteen', 'item_fourteen', 'item_fifthteen')";

并尝试执行

$result = mysql_query($order);

根据您的评论尝试执行插入查询,例如

CREATE TABLE IF NOT EXISTS `requested_inventory`
(name varchar(20), email varchar(20), item_one varchar(20), item_two varchar(20), item_three varchar(20), item_four varchar(20), item_five varchar(20), item_six varchar(20), item_seven varchar(20), item_eight varchar(20), item_nine varchar(20), item_ten varchar(20), item_eleven varchar(20), item_twelve varchar(20), item_thirteen varchar(20), item_fourteen varchar(20), item_fifthteen varchar(20));

您可以根据您的要求更改数据类型

于 2013-07-10T05:32:52.183 回答
1

改变这个

$result = mysql_query('$order');

$result = mysql_query($order);

内部单引号变量被视为普通文本。使用直接变量名称或将其括在双引号中。

于 2013-07-10T05:36:29.343 回答
0
<?php

$order = "INSERT INTO requested_inventory
            (name, email, item_one, item_two, item_three, item_four, item_five, item_six, item_seven, item_eight, item_nine, item_ten, item_eleven, item_twelve, item_thirteen, item_fourteen, item_fifthteen)
            VALUES
            ('$_REQUEST[name]',
            '$_REQUEST[email]', '$_REQUEST[item_one]', '$_REQUEST[item_two]', '$_REQUEST[item_three]', '$_REQUEST[item_four]', '$_REQUEST[item_five]', '$_REQUEST[item_six]', '$_REQUEST[item_seven]', '$_REQUEST[item_eight]', '$_REQUEST[item_eight]', '$_REQUEST[item_nine]', '$_REQUEST[item_ten]', '$_REQUEST[item_eleven]', '$_REQUEST[item_twelve]', '$_REQUEST[item_thirteen]', '$_REQUEST[item_fourteen]', '$_REQUEST[item_fifthteen]')";

//declare in the order variable
$result = mysql_query($order);    //order executes

?>

也添加mysql_real_escape_string到您的查询

也通知你mysql_query不再支持

于 2013-07-10T05:41:47.937 回答
0
$result = mysql_query($order); 

替换它并请检查 id 字段是否自动递增或不也请提供您收到的错误消息

于 2013-07-10T05:35:49.977 回答