Page 1 of 1

Dropping an array into a MySQL table

Posted: Fri Oct 13, 2006 6:14 am
by impulse()
If I have an array with several items contained within, how would it be possible to drop the contents into a MySQL DB?

For example:

Code: Select all

$i[ID][NAME][AGE]
if that was my array and I had 3 columns in the MySQL table (ID, name, age), how would I insert everything in the array into the table.

Posted: Fri Oct 13, 2006 10:18 am
by Oren
Hmm... Maybe you meant to this?

Code: Select all

$i[ID]
$i[NAME]
$i[AGE]
ID, NAME and AGE are constants right? If they are not, wrap them with ' (single quote).

Posted: Fri Oct 13, 2006 10:22 am
by impulse()
Yeah, I had a dumb moment

:)

Posted: Fri Oct 13, 2006 10:35 am
by Oren

Code: Select all

$sql = "INSERT
	INTO    `tbl_name` (id, name, age)
	VALUES  ('$i[ID]', '$i[NAME]', '$i[AGE]')";
Assuming ID, NAME and AGE are constants.