views:

47

answers:

1

Why is the table filled with Array[0], Array[1], Array[2], Array[3] after the following SQL statement is executed?

 mysql_query("INSERT INTO choicetable (announcementid, question, option1, option2, option3, option4) 
   VALUES ('$announcementid', '$choicequestion[$j]', '$option[$j][0]', '$option[$j][1]', '$option[$j][2]', '$option[$j][3]')")
 or die(mysql_error());

When I echo $option[$j][0];, it displays the true value. But the value of $option[$j][0], $option[$j][1], $option[$j][2], $option[$j][3] cannot be inserted into the table. What's wrong?

I am using MySQL.

+3  A: 

You need to wrap the array elements in braces, e.g.,

"{$option[$j][3]}"

See the PHP Manual page for strings; it's under the heading "Variable Parsing."

James McNellis