problem reciving check box values using post method
Hi all i got a form with many checkboxes and i want to pass checkbox varaibles to a new page using post method but the problem is that each time the first variable get pasted .Beleow u see part of php code that recives the passed variables. When i run this script by selecting 3 check boxes which has values :1 first check box, 2 second checkbox and 3 3th checbox. i get this
select filename,title from wimpy where id=1
instead of
select filename,title from wimpy where id=1 OR id=2 OR id=3
I be happy if an expert help me fix this problem and be able to pass all values of check box to second page and be able to buil query such :
select filename,title from wimpy where id=1 OR id=2 OR id=3
Thanks
part of check box form code:
Code:
<form method="POST" action="./playlist.php" name="mp3Play">
...
...
...
playlist.php code
Code:
<?php
//echo $_POST['id'];
$user = "root";
$pw = "";
$db = "mp3sversion5";
$mysql_access = mysql_connect("localhost", $user, $pw);
mysql_select_db($db, $mysql_access);
if (isset($_POST['Id'])) {
$fragments = explode(',',$_POST['Id']);
$loopCount = sizeof($fragments);
for ($loop = 0; $loop < $loopCount; $loop++) {
if ($where != '') $where .= ' OR';
$where .= ' id='.$fragments[$loop].' ';
}}
$query = "select filename,title from wimpy where $where";
echo $query;
$result = mysql_query($query);
Re: problem reciving check box values using post method
Can you post the HTML? What you need to do is give all the checkboxes a name of "id[]". PHP will then turn it into an array at the server side.
Re: problem reciving check box values using post method
tony007, instead of posting a new post for every issue you reach with the same part of your code, just continue on with the previous posting. Like visualAd said and I told you in another post involving passing your checkboxes, you need to name them all the same name, like "id". PHP will then assign them to an array and you can then loop through for the size of the array and get each of the individual answers, then you would not need to do the explode.
Re: problem reciving check box values using post method
Quote:
Originally Posted by visualAd
Can you post the HTML? What you need to do is give all the checkboxes a name of "id[]". PHP will then turn it into an array at the server side.
Thanks for u reply. Here is part of my html code:
Code:
<td width="3%">
<input type="checkbox" name="id" value="<?=strval( $row['id'] );?>" checked></td>
<td width="50%"><?=strval( $row['title'] );?></b> </td>
<td width="20%"><?=strval( $row['album'] );?> </td>
<td width="10%">D </td>
<td width="5%">33 </td>
</tr>
Re: problem reciving check box values using post method
RE:To
"""""""""""""""""""""""""""""""
<?php
//echo $_POST['id'];
$user = "root";
$pw = "";
$db = "mp3sversion5";
$mysql_access = mysql_connect("localhost", $user, $pw);
mysql_select_db($db, $mysql_access);
if (isset($_POST['Id'])) {
$fragments = explode(',',$_POST['Id']);
$loopCount = sizeof($fragments);
for ($loop = 0; $loop < $loopCount; $loop++) {
if ($where != '') $where .= ' OR';
$where .= ' id='.$fragments[$loop].' ';
}}
$query = "select filename,title from wimpy where $where";
echo $query;
$result = mysql_query($query);
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"
where u have $query = "select filename,title from wimpy where $where;" you have a snytax error it should look like this
$query = "select filename,title from wimpy where".$where;