Go Back   Access World Forums > Apps and Windows > Web Design and Development

 
Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average. Display Modes
Old 02-19-2006, 11:36 PM   #1
tony007
Registered User
 
Join Date: Jun 2005
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
tony007 is on a distinguished road
Arrow 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);

tony007 is offline   Reply With Quote
Old 02-20-2006, 03:48 AM   #2
Kodo
"The Shoe"
 
Kodo's Avatar
 
Join Date: Jan 2004
Location: Syracuse NY
Posts: 707
Thanks: 0
Thanked 1 Time in 1 Post
Kodo is on a distinguished road
Send a message via MSN to Kodo
if the checkboxes have the same name ("POSTID") then they are posted as a concatenated string with comma's as the delimeter, like so. 1,3,6,29,93 and so on and so on. If MySQL supports the "IN" keyword (and I'm sure it does), you won't need to do that, just do:
$query = "select filename,title from wimpy where id IN($_POST['Id'])";
__________________
Message boards: The only place where multiple personality disorders are treated with a "welcome" post.
Kodo is offline   Reply With Quote
Old 02-20-2006, 10:28 AM   #3
tony007
Registered User
 
Join Date: Jun 2005
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
tony007 is on a distinguished road
Arrow

Quote:
Originally Posted by Kodo
if the checkboxes have the same name ("POSTID") then they are posted as a concatenated string with comma's as the delimeter, like so. 1,3,6,29,93 and so on and so on. If MySQL supports the "IN" keyword (and I'm sure it does), you won't need to do that, just do:
$query = "select filename,title from wimpy where id IN($_POST['Id'])";
Many thanks for u reply i tried your suggestion and i got the following error:

Code:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in file.php on line 19
I be happy if u help me fix this problem.Thanks

Code:
<?php



$user = "root";
$pw = "";
$db = "test2";
$mysql_access = mysql_connect("localhost", $user, $pw);
mysql_select_db($db, $mysql_access);

$query = "select * from files where id IN($_POST['Id'])"; ===>line 19

echo $query;

 $result = mysql_query($query) or die("Error with MySQL Statement! ".mysql_error()."<br>\nThe query was ".$query);

?>

<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="70%" id="AutoNumber1">

	<form action="/Members/AddToPlayList.php" method=post >
	<input name="go" type="hidden" value="yes">
    <tr>
      <td width="20%" height="23">Add to Playlist:
      </td>
      <td width="50%" height="23">
      	<select size="1" name="List">
      		
      		<option value="2187">wow</option>
      		
      	</select>
      </td>
    </tr>
    
    <tr>
      <td colspan=2 height="1">
      		<table border="1">
 				 <tr>
    				<td width="3%">&nbsp;</td>
   					<td width="50%"><b>Song Name</b></td>
    				<td width="20%"><b>Album</b></td>
    				<td width="10%"><b>Language</b></td>
    				<td width="5%"><b>Hits</b></td>
  				</tr>

<?
while($row = mysql_fetch_assoc($result))
{
    //echo "<br>path : {$row['filename']} <br>" .
      //   "title :{$row['title']} <br>";


?>
 <tr>
    				<td width="3%"><input type="checkbox" name="id" value="<?=strval( $row['id'] );?>" checked></td>
   					<td width="50%"><?=$title ;?></b>&nbsp;</td>
    				<td width="20%"><?=strval( $row['album'] );?>&nbsp;</td>
    				<td width="10%">D&nbsp;</td>
    				<td width="5%">33&nbsp;</td>
  				</tr>

<?
  

}



?>



	  
      		</table>
      </td>
    </tr>
    
    
    <tr>
      <td colspan=2 height="27">
      <p align="center">
      <input type="submit" value="Add this/these Songs to my PlayList" name="B1">
      </td>
    </tr>
    </form>
  </table>
  </center>
</div>
</body>
checkbox code;

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

tony007 is offline   Reply With Quote
Old 02-20-2006, 12:37 PM   #4
Kodo
"The Shoe"
 
Kodo's Avatar
 
Join Date: Jan 2004
Location: Syracuse NY
Posts: 707
Thanks: 0
Thanked 1 Time in 1 Post
Kodo is on a distinguished road
Send a message via MSN to Kodo
PHP isn't my language so I'm taking a pot shot at the syntax...

$query = "select * from files where id IN(" + $_POST['Id']+ ")";
__________________
Message boards: The only place where multiple personality disorders are treated with a "welcome" post.
Kodo is offline   Reply With Quote
Old 02-20-2006, 03:59 PM   #5
tony007
Registered User
 
Join Date: Jun 2005
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
tony007 is on a distinguished road
Quote:
Originally Posted by Kodo
PHP isn't my language so I'm taking a pot shot at the syntax...

$query = "select * from files where id IN(" + $_POST['Id']+ ")";

Code:
Fatal error: Unsupported operand types in file.php on line 18



and pointing to the same line where the query is !!:-(
tony007 is offline   Reply With Quote
Old 02-20-2006, 05:23 PM   #6
Kodo
"The Shoe"
 
Kodo's Avatar
 
Join Date: Jan 2004
Location: Syracuse NY
Posts: 707
Thanks: 0
Thanked 1 Time in 1 Post
Kodo is on a distinguished road
Send a message via MSN to Kodo
ok.. I had the syntax really close.. try this
$query = "SELECT * fROM files WHERE id IN(".$_POST['id'].")";

__________________
Message boards: The only place where multiple personality disorders are treated with a "welcome" post.
Kodo is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with combo box on datasheet subform madhouse Forms 6 06-03-2008 05:58 AM
Simple combo box solution, difficult problem description etalent Forms 1 03-26-2004 10:14 AM
Check Box problem elsanto General 1 07-22-2003 10:34 PM
Update list box based on state of check box bwyrwitzke General 2 11-14-2002 06:27 PM
List Box Values as Query parm for a Report Opengrave Reports 2 07-03-2002 10:29 AM




All times are GMT -8. The time now is 09:11 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World