problem reciving check box values using post method

Joined
Jun 30, 2005
Messages
59
Reaction score
0
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);


[B]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].' ';
	}[/B]}
$query = "select filename,title from wimpy where $where";

[B]echo $query;[/B]

[B]$result = mysql_query($query);[/B]
 
Joined
Mar 17, 2005
Messages
159
Reaction score
0
$_POST['Id'] is a scalar (non list) value,. post more of the html code where you setup the checkboxes?

Sil
 
Joined
Jun 30, 2005
Messages
59
Reaction score
0
silver said:
$_POST['Id'] is a scalar (non list) value,. post more of the html code where you setup the checkboxes?

Sil

first page that sends data to next page :


Code:
 [/b]
[b]<form method="POST" action="./Members/AddToPlayList.php" name="mp3Play"> 						 <tr>[/b]
 
?>
while($row = mysql_fetch_assoc($result))
{
 
<td bgcolor="#C0C0C0"><p align="center"><b><?=intval( $row['track'] );?></b></p>
						</td>
						<td bgcolor="#C0C0C0">
 
[b]<input[/b]
[b]						type="checkbox" name="Id" value='<?=intval( $row['id'] );?>' /></td>[/b]
 
						<td bgcolor="#C0C0C0"><a
						href="[url="http://www.tek-tips.com/viewthread.cfm?qid=1193798&page=1#"]javascript[/url]:newWindow('./mp3s/myWimpy.php?queryWhere=Id&queryValue=<?=strval( $row['id'] );?>')"><img
						src="images/Speaker.gif"
						alt="Listen to this Song" border="0"
						width="16" height="16"
						longdesc="Listen to this Song"></a> ;<?=strval( $row['title'] );?>
						</td>
						<td bgcolor="#C0C0C0"> <?=strval( $row['album'] );?> </td>
						<td bgcolor="#C0C0C0"><a
						href="javascript:newWindow('RateSong.asp?SongID=1')"><img
						src="images/RatIt.gif"
						alt="Rate This Song" border="0"
						width="100" height="22"
						longdesc="Rate This Song"></a></td>
						<td align="center" bgcolor="#C0C0C0">0 </td>
						<td bgcolor="#C0C0C0">coming Soon <!-- <a href="../site.php?songID=1&Song=Atash">Read </a>| <a href="./Members/WriteLyrics.php?SongId=1&Song=Atash">Write</a> --> </td>
<?
 
 
} //end of while
[b] ....[/b]
[b].....[/b]
[b].....[/b]
[b]
 
Joined
Mar 17, 2005
Messages
159
Reaction score
0
yeah - it's not going to work (as you found out!) :)

essentially, you need the part that says

type="checkbox" name="Id" value='<?=intval( $row['id'] );?>' /></td>

to be more like

type="checkbox" name="Id_$row['id']"value='<?=intval( $row['id'] );?>' /></td>

or something, since name="Id" would only be one variable - which can take only one value, so you need a unique name for each of the values,. actually there's probably a way to code multiple select checkboxes in php but I don't know offhand

if you use Id_$row['id'] as the name and when the form comes go through the post variables and look for stuff starting 'Id_' ?

Sil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top