View Full Version : Insert record using array from a form...

01-30-2007, 10:11 AM
where is my mistake? :roll:



if ($_POST['button]=="Continue")

echo " <FORM name='insert' method='post' action='insert.php'>
<td bgcolor='#DCDCDC'><b>Number</b></td>
<td bgcolor='#DCDCDC' width=180><b>Question</b></td>

for ($i=1; $i<=$questionTotal; $i++){
echo "
<td bgcolor='#E6E6FA'><b>$i</b></td>
<td bgcolor='#E6E6FA'><textarea id=list name=questionlist cols=20 rows=2></textarea></td>

} //end while

echo "</table><br>
<input type='submit' name='Save' value='Save'>&nbsp;&nbsp;<input type='reset' name='Reset' value='Reset'>
$questionlist = $_POST['questionlist'];



<? include 'db.php';


if(isset ($_POST['questionlist']))
$n = count($questionlist);

for ($i=1; $i<=$n; $i++){
mysql_query("insert into soalan (soalan) values
('$questionlist')") or die (mysql_error());
} // end while
} // end if

01-30-2007, 10:17 AM
your questionlist <textarea is not set as an array

you have ...

<textarea id=list name=questionlist cols=20 rows=2>

should this not be ...

<textarea id=list name=questionlist[] cols=20 rows=2>

01-30-2007, 10:28 AM
thanks for the reply david.. i had put the term in right condition as


but it appear an error in line -- $questionlist = $_POST['questionlist'];

the error is --
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

should i change the declaration or...what should i do..thanks for your concerning...

01-30-2007, 10:36 AM
in your mypage.php you have

<textarea id=list name=questionlist cols=20 rows=2>

first you should have your attribute values in quotes and your name should be set as an array because you are looping through lots of <textareas
<textarea id="list" name="questionlist[]"cols="20" rows="2">

are you getting this error when you submit or when you load the page?

01-30-2007, 10:53 AM
sir, if i put the double code (") it appear an error below-->

Parse error: parse error, expecting `','' or `';''

i get the error -->
parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

when i click the submit button.. is the variable not declaire rightly? actually, before i mention the coding ---->$questionlist = $_POST['questionlist'];
the array can submit to database but it doesnt send the right value as inserted while running..sory if i disturbing your time....

01-30-2007, 10:57 AM
try using \

which means literal quote

<textarea id=\"list\" name=\"questionlist[]\"cols=\"20\" rows=\"2\">

01-30-2007, 11:47 AM
it doesnt work also...
anyway..thanks a lot..=)

01-30-2007, 01:19 PM
can you list what you are doing. i.e. the first page you start at through to where you expect to insert the record, and include what variables you are passing to each page.

this way it will be easier to see exactly what you are trying to do and how you are trying to do it


01-30-2007, 01:24 PM

whats all the transformer shite about?

try this one


01-30-2007, 02:30 PM
this any better! hahaha, tw*t!