php how to write query to retrieve data from checkbox that have been choose

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • micropos
    New Member
    • Aug 2010
    • 4

    php how to write query to retrieve data from checkbox that have been choose

    hi everyone,who can help me solve the problem?this is my code:

    Code:
    <?php
    
    include 'C:/wamp/www/micropos/condb1.php';
    
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("customer", $con);
    
    $i=0;
    $i++;
    for($i=0;$i<0;$i++){
    $amount = $_POST[''.$i];
    }
    
    for($i=1;$i<3;$i++){
       if(isset($_POST['cd'.$i]) && $_POST['cd'.$i] == 'checked')
    
    	{
    	    echo " Access.";
    	}
    	else
    	{
                      echo isset($_POST['$i']);
    	    echo "Do not access.";
    	}	
    
    
    }
    
    
    if(isset($_POST['submit'])){
     echo "checked";
    }
    else
    {
      echo "unchecked";
    }
    
    
    $username=$_POST[''];
    $query = "SELECT * FROM reg_form WHERE username='ks'";
    $query = "SELECT * FROM reg_form WHERE username='kodis'";
    
    
    $result = mysql_query($query)
            or die("SELECT Error: ".mysql_error());
    $num_rows = mysql_num_rows($result);
    print "There are $num_rows records.<P>";
    print "<table width=800 border=1>\n";
    while ($get_info = mysql_fetch_row($result)){
    
          print "<tr>\n";
    
          foreach ($get_info as $field)
                  print "\t<td><font face=arial size=3/>$field</font></td>\n";
    
                  print "<input type=\"hidden\" name=\"username\" value=\"$get_info[1]\">";
    
    
                  print "</tr>\n";
    
    }
    print "</table>\n";
    
    
    ?>
    the problem is i wan print out the whole rows of checkbox values that have been choose?what query should i write????
    please help me to solve the problem.thanks
    Last edited by Dormilich; Aug 16 '10, 10:13 AM. Reason: Please use [code] tags when posting code
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    your question is not clear enough, you didnt describe what are you trying to achieve.

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      There are many problems in your original code. Too many to list.

      I suggest reducing your code to very 1 very simple function. Make it work, or ask here if you get stuck, then move on to adding more functionality.

      example: line 45, 46. why are you storing two sql strings in the same variable? The last one will always take affect because you're over writing the first one.

      There are many tutorials online to get you started on PHP and HTML Form -> checkbox programming.


      Dan

      Comment

      • micropos
        New Member
        • Aug 2010
        • 4

        #4
        can u teach me how to write query to retrieve data from checkbox?means if we ticked 3 rows,then it will cum out 3 rows of data.thanks.

        Comment

        • johny10151981
          Top Contributor
          • Jan 2010
          • 1059

          #5
          how check box and rows are connected? I am not sure about your question.
          Even though i am answering with what i have understood from your question...

          say you have 3 check box
          Code:
          <form action="x.php" method=GET>
          <input type=checkbox name=c1>
          <input type=checkbox name=c2>
          <input type=checkbox name=c3>
          <input type=submit name=submit>
          </form>
          say if you check c1 and c3 on, your x.php you will have
          $_GET['c1'] and $_GET['c3'] but you wont get $_GET['c2']. Even if you try to use $_GET['c2'] you will get an undefined index error.

          but you can check this way

          Code:
          if(isset($_GET['c1'])==true)
          {
          //  ...............
          //  do your task
          }
          if(isset($_GET['c2'])==true)
          {
          //  ...............
          //  do your task
          }
          if(isset($_GET['c3'])==true)
          {
          //  ...............
          //  do your task
          }
          Even though I must say, you question is not clear. I guess you are not clear with your need.

          Comment

          Working...