PDA

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


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

mypage.php

<?

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

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

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

} //end while

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

}
?>



insert.php

<? include 'db.php';

$questionlist=$_POST['questionlist'];

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

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

davidj
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>

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

name=questionlist[]

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...

davidj
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?

illa_arm
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....

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

which means literal quote


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

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

lux
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

regards

davidj
01-30-2007, 01:24 PM
lux

whats all the transformer shite about?

try this one

http://www.youtube.com/watch?v=dyqEPgRc6IE

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