•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 361,552 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,037 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1333 | Replies: 1
![]() |
•
•
Join Date: May 2008
Location: Hyderabad,India
Posts: 89
Reputation:
Rep Power: 1
Solved Threads: 0
<?php
include("conn.php");
include("session.php");
?>
<html>
<head>
<title></title>
</head>
<body>
<form action="user.php" method="post">
<table border="0" align="center" width="100%">
<tr>
<td align="center"><a href="editevent.php">Edit Event</a></td>
<td align="center"><a href="addevent.php">Add Event</a></td>
<td align="right"><a href="logout.php">Logout</a></td>
</tr>
<tr>
<td colspan="3"><b>List of events</b></td></tr>
<?php
$str="SELECT * FROM eventdesc ";
$res=mysql_query($str);
if(mysql_num_rows($res)!=0)
{
while($data=mysql_fetch_array($res,MYSQL_ASSOC))
{
echo '<tr> <td>'. $data['eventdesc'].'</td> <td> <input type="checkbox" name="chkbx[]" ></td></tr>';
}
}
mysql_close();
?>
<tr><td align="right"><input type="submit" Value="Display"></td></tr>
</table>
</form>
</body>
</html>Here is my code for user.php
<?php
include("conn.php");
include("session.php");
$str= foreach($_POST["chkbx"] AS $key => $value){
"INSERT INTO eventdesc(show) VALUES
('{$_POST["chkbx"][0]} {$_POST["chkbx"][1]} {$_POST["chkbx"][2]} {$_POST["chkbx"][3]} {$_POST["chkbx"][4]} {$_POST["chkbx"][5]} {$_POST["chkbx"][6]} {$_POST["chkbx"][7]} {$_POST["chkbx"][8]} {$_POST["chkbx"][9]} {$_POST["chkbx"][10]} {$_POST["chkbx"][11]} {$_POST["chkbx"][12]} {$_POST["chkbx"][13]} {$_POST["chkbx"][14]} {$_POST["chkbx"][15]} {$_POST["chkbx"][16]} {$_POST["chkbx"][17]} {$_POST["chkbx"][18]} {$_POST["chkbx"][19]} {$_POST["chkbx"][20]} {$_POST["chkbx"][21]} {$_POST["chkbx"][22]} {$_POST["chkbx"][23]} {$_POST["chkbx"][24]} {$_POST["chkbx"][25]} {$_POST["chkbx"][26]} {$_POST["chkbx"][27]} {$_POST["chkbx"][28]} {$_POST["chkbx"][29]} {$_POST["chkbx"][30]} {$_POST["chkbx"][31]}')");
}
$res=mysql_query($str);
if($res)
echo 'Success';
else
echo 'Failure';
mysql_close($con);
?>
and this the error am getting:
Parse error: syntax error, unexpected T_FOREACH in C:\Program Files\xampp\htdocs\exphp\Events\Myevents\user.php on line 6
what shall i do to slove this?
•
•
Join Date: May 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 1
I think for multiple check boxes insert, you have to coding like this in your php file
$c=$_REQUEST['chkbx'];
for($i=0;$i<count($c);$i++)
{
$val=$c[$i];
$sql="INSERT INTO eventdesc(show) VALUES($val);
$res=mysql_query($sql);
}
By this coding,you can insert all check boxes values in your DB which are checked.
$c=$_REQUEST['chkbx'];
for($i=0;$i<count($c);$i++)
{
$val=$c[$i];
$sql="INSERT INTO eventdesc(show) VALUES($val);
$res=mysql_query($sql);
}
By this coding,you can insert all check boxes values in your DB which are checked.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Variable passed to each() is not an array (PHP)
- Storing dynamic form values in Arrays for display & insert (PHP)
Other Threads in the PHP Forum
- Previous Thread: pagination that contains specified letter
- Next Thread: Export to CVS with color


Linear Mode