0
$transaction->setFields(
    array(
    'first_name' => $_POST['x_first_name'],
    'last_name' => $_POST['x_last_name'],
    )

mysql_query("INSERT INTO table_one (`first_name`, `last_name`) 
    VALUES ("$transaction->setFields['x_first_name']",'last_name')");

从这个数组调用有问题,必须是语法,但我找不到很好的参考。

4

3 回答 3

0

数组与否,当您从双引号内访问变量时,请始终使用大括号。

mysql_query("INSERT INTO table_one (`first_name`, `last_name`) 
VALUES ("{$array['x_first_name']}",'{$array['last_name']}')");

如果您可以在此页面中搜索“复杂(卷曲)语法”,您可以找到更多信息:http: //php.net/manual/en/language.types.string.php

于 2013-03-12T17:52:08.623 回答
0

您的数组缺少 a);并且最后一个元素有一个尾随逗号。此外,您在查询中的引号是错误的。试试这个:

$transaction -> setFields(array('first_name' => $_POST['x_first_name'], 'last_name' => $_POST['x_last_name']));
mysql_query("INSERT INTO table_one (`first_name`, `last_name`) VALUES ('" . $transaction -> setFields['x_first_name'] . "','last_name')");
于 2013-03-12T17:52:26.237 回答
0

很高兴看到$transaction. 也许使用 SPL Array/Iterator 之类的?假设没有其他吸气剂,但也许有getFields()?

$fields = $transaction->getFields();

或者只使用您在 setter 中传递的数组。无论哪种方式,使用[]...

mysql_query("INSERT INTO table_one (`first_name`, `last_name`) 
VALUES ("{$fields['x_first_name']}",'last_name')");

在PDO和正在折旧的 mysql_*上插入简介...

于 2013-03-12T17:54:46.310 回答