Results 1 to 5 of 5

Thread: problem reciving check box values using post method

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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);
    Last edited by tony007; Feb 20th, 2006 at 02:30 AM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    Fanatic Member neicedover1982's Avatar
    Join Date
    Jun 2005
    Posts
    566

    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.
    Kevin | New England Iced Over | http://www.kevincawleyjr.com

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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>&nbsp;</td>
        				<td width="20%"><?=strval( $row['album'] );?>&nbsp;</td>
        				<td width="10%">D&nbsp;</td>
        				<td width="5%">33&nbsp;</td>
      				</tr>

  5. #5
    New Member
    Join Date
    Jul 2008
    Posts
    1

    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width