Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 20th, 2006, 02:38 AM
ehsanking ehsanking is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 207 ehsanking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 3 m 51 sec
Reputation Power: 4
Arrow Problem reciving check box values using post method in php

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);

Reply With Quote
  #2  
Old February 26th, 2006, 03:00 PM
EvilSimon EvilSimon is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 18 EvilSimon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 2 m 47 sec
Reputation Power: 0
1) Stop posting the same question

2) Tell PHP that the incoming post data is an array ( i.e. label your form fields as id[]

3) Use IN ( .. )

PHP Code:
// off the top of my head, but should give you an idea.
if (isset($_POST['id'])) 
{
   
$where = array( );
   foreach( 
$_POST'id' ] as $id )
   {
       
// add each value to our where array, after (crudely) making sure it's a number
       
$where[] = (int) $id;
   }
   
$where implode', '$where );
   
$query 'select filename,title from wimpy where in IN ( '.$where.')';

   echo 
$query;


Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Problem reciving check box values using post method in php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT