This isn't anything overly complicated (I assume), I'm just not sure of the syntax for doing what I want. I'm trying to insert a value from an array into the database. Below achieves what I want to do, however I was wondering if it could be reformatted to the code below that.
Current code which does what I want:
$name = explode(" ",$fullName);
$firstName = $name[0];
$lastName = $name[count($name) - 1];
mysql_query("INSERT INTO `person` VALUES(NULL, '$firstName', '$lastName',0)"));
What I want to know is if it can be formatted like this:
$name = explode(" ",$fullName);
mysql_query("INSERT INTO `person` VALUES(NULL, '$name[0]', '$name[count($name) - 1]',0)"));
I tried this earlier a few different ways and got an error, is it just an issue with syntax or is it something a bit deeper?
Oh, and I should add that the only time I actually got the insert to run fully, I ended up with Array[0] and Array[2] - 1 in the first_name and last_name columns respectively.
Thanks all, hopefully I've been clear enough. Need any more info, let me know.
$name = explode(" ",$fullName); mysql_query("INSERT INTO 'person' VALUES(NULL, '$name[0]', '$name[count($name) - 1]');This code fetched an error?? What was the error? Formatting looks fine.mysql_query("INSERT INTO person VALUES(NULL, '$name[0]', '".($name[count($name) - 1])."')");more like this ..