Hi,

Not sure if this is the best place to post this but i'm having problems trying to insert the following into my db using mysqli. I keep getting unexpected '-' or unexpected T_VARIABLE errors.

Any idea how i can solve this please?

$query = "INSERT INTO the_transactions VALUES (
	'$my_var',
	'$page_one[input-one]',
	'$page_one[check-one]',
	'$page_one[title]',
	)";

Comments

Anonymous’s picture

You should really use the database API for this to prevent injection attacks, something like this:

db_query("INSERT INTO {the_transactions} VALUES ('%s', '%s', '%s', '%s')", $my_var, $page_one['input-one'], $page_one['check-one'], $page_one['title']);

'unexpected T_VARIABLE' errors are usually because you're code's missing a curly brace or there's a space between <? and php at the beginning of the file, something like that.

rix.kostenko’s picture

Didn't even realise there was a database api - thanks!

Anonymous’s picture

use 'drupal_write_record' instead

http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_wr...

 $data = array(
    'fieldname1' => $my_var,
    'fieldname2' => $page_one['input-one'],
    'fieldname3' => $page_one['check-one'],
    'fieldname4' => $page_one['title']
  );
  drupal_write_record('the_transactions', $data);