Forum Moderators: coopster

Message Too Old, No Replies

Inserting muliple record and Parse error

         

Shanee

7:46 am on Dec 1, 2007 (gmt 0)

10+ Year Member



i want to insert multiple records from one form. i have created a little code for it. but i am getting error

Parse error: parse error in \insert-muliple-records.php on line 52

FORM
<form method="POST" action="">
<input type="checkbox" name="id[]" value="32">Article #32<br>
<input type="checkbox" name="id[]" value="38">Article #38<br>
<input type="checkbox" name="id[]" value="45">Article #45<br>
<input type="checkbox" name="id[]" value="59">Article #59<br>
<input type="hidden" name="referer" value="123">
<input name="action" type="Submit" id="action" value="Submit">

PHP Code :

<?
if($action = Submit){
foreach ($_POST['id']) as $id) {
$sql = "insert into keywords (id, referer) values ($id, '$referer')";
$result = mysql_query($sql ,$db);
}
}
?>

please help me how to solve this problem

dreamcatcher

3:37 pm on Dec 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The parse error is probably down to this line:

foreach ($_POST['id']) as $id) {

You have too many parenthesis.

foreach ($_POST['id'] as $id) {

You should also check that the post array is not empty before using a foreach loop. Try running the code with no boxes selected and see what happens.

Also, this line isn`t right:

if($action = Submit){

Try simply:

if(isset($_POST['action'])){

dc