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')");

Having issues calling from this array, has to be syntax but i cannot find a good reference.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
user2162192
  • 151
  • 8
  • What is `$transaction->setFields`? P.S. You're missing a `);` – gen_Eric Mar 12 '13 at 17:47
  • Lets assume the arrays created correctly.. how would you call from it? – user2162192 Mar 12 '13 at 17:49
  • So `$transaction->setFields` *is* an array (not a function)? – gen_Eric Mar 12 '13 at 17:49
  • It depends on the type of object transaction is. Is it possible you are looking for something like $transaction->getFields('x_first_name');? Also, you shouldn't use mysql_query as it is to be deprecated and if the $transaction->setFields() function is not sanitizing the input data you should really do so using something like mysql_escape_string() or bindings. – Joe Meyer Mar 12 '13 at 17:49

3 Answers3

0

Array or not, always use curly brackets when you're accessing a variable from inside of double quotes.

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

You can find more information if you can search for "Complex (curly) syntax" in this page: http://php.net/manual/en/language.types.string.php

Tim
  • 699
  • 8
  • 27
0

Your array is missing a ); and there is a trailing comma on the last element. Also, your quotes in the query are wrong. Try this:

$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')");
SeanWM
  • 16,789
  • 7
  • 51
  • 83
0

Would be good to see declaration of $transaction. Maybe uses SPL Array/Iterator or something? Assuming no other getters though maybe there is a getFields()?

$fields = $transaction->getFields();

Or just use the array you passed in the setter. Either way something like this using []...

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

Insert blurb on PDO and mysql_* being depreciated...

Community
  • 1
  • 1
ficuscr
  • 6,975
  • 2
  • 32
  • 52