Try $answers["answer".$n]

---
Scott Hurring
Systems Programmer
EAC Corporation
[EMAIL PROTECTED]
Voice: 201-462-2149
Fax: 201-288-1515

> -----Original Message-----
> From: Jule [mailto:[EMAIL PROTECTED]]
> Sent: Friday, May 17, 2002 4:41 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] $answers[answer$n]
> 
> 
> Hey guys,
> i'm getting this error whe i try to access this variable. 
> $answers[answer$n]
> 
> Parse error: parse error, expecting `']'' in 
> /home/blindtheory/web/quiz/add_quiz/add_quiz_process_2.php on line 36
> 
> the variable $answer[answers$n] comes from a form on the 
> preceding page in 
> which a number of answers has been entered. the number of 
> answers is up to 
> the user and can vary from 2 to 15. not the $n comes from a 
> for loop whcih 
> enteres the answers into a database since i do not know how 
> many answers each 
> user has used.
> 
> why am i getting this error?
> and is there a way around it?
> following is the for() loop in which this story takes place.
> 
> thanks
> Jule
> 
> --SCRIPT--
> 
> for ($n = 1; $n <= $quiz[number_answers]; $n++) {
>                       $table = "$quiz[code]_answers";
>                       $value = "$answers[answer$n]";
>                       $query_alter_table = "ALTER table 
> $table ADD answer$n TEXT NUT NULL";
>                       $query_add_answers = "INSERT INTO 
> $table (answer$n) VALUES($value)";
>                       if (mysql_db_query($database_glob, 
> $query_alter_table, $link_glob) AND 
> (mysql_db_query($database_glob, $query_add_answer, $link_glob));
>                               echo "Answer $n has 
> successfully been added to the Quiz<br>\n";
>                       } else { 
>                               echo mysql_error();
>                       }
>                               echo "Click here to continue";
> }
> 
> --SCRIPT--
> 
> -- 
> |\/\__________________________/\/|
> |   Jule Slootbeek             |
> |   [EMAIL PROTECTED]      |
> |   http://blindtheory.cjb.net         |
> |   __________________________         |
> |/\/                        \/\|
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to