By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,543 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,543 IT Pros & Developers. It's quick & easy.

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

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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include 'C:/wamp/www/micropos/condb1.php';
  4.  
  5. $con = mysql_connect("localhost","root","");
  6. if (!$con)
  7.   {
  8.   die('Could not connect: ' . mysql_error());
  9.   }
  10.  
  11. mysql_select_db("customer", $con);
  12.  
  13. $i=0;
  14. $i++;
  15. for($i=0;$i<0;$i++){
  16. $amount = $_POST[''.$i];
  17. }
  18.  
  19. for($i=1;$i<3;$i++){
  20.    if(isset($_POST['cd'.$i]) && $_POST['cd'.$i] == 'checked')
  21.  
  22.     {
  23.         echo " Access.";
  24.     }
  25.     else
  26.     {
  27.                   echo isset($_POST['$i']);
  28.         echo "Do not access.";
  29.     }    
  30.  
  31.  
  32. }
  33.  
  34.  
  35. if(isset($_POST['submit'])){
  36.  echo "checked";
  37. }
  38. else
  39. {
  40.   echo "unchecked";
  41. }
  42.  
  43.  
  44. $username=$_POST[''];
  45. $query = "SELECT * FROM reg_form WHERE username='ks'";
  46. $query = "SELECT * FROM reg_form WHERE username='kodis'";
  47.  
  48.  
  49. $result = mysql_query($query)
  50.         or die("SELECT Error: ".mysql_error());
  51. $num_rows = mysql_num_rows($result);
  52. print "There are $num_rows records.<P>";
  53. print "<table width=800 border=1>\n";
  54. while ($get_info = mysql_fetch_row($result)){
  55.  
  56.       print "<tr>\n";
  57.  
  58.       foreach ($get_info as $field)
  59.               print "\t<td><font face=arial size=3/>$field</font></td>\n";
  60.  
  61.               print "<input type=\"hidden\" name=\"username\" value=\"$get_info[1]\">";
  62.  
  63.  
  64.               print "</tr>\n";
  65.  
  66. }
  67. print "</table>\n";
  68.  
  69.  
  70. ?>
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
Aug 16 '10 #1
Share this Question
Share on Google+
4 Replies


100+
P: 1,059
your question is not clear enough, you didnt describe what are you trying to achieve.
Aug 16 '10 #2

dlite922
Expert 100+
P: 1,584
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
Aug 16 '10 #3

P: 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.
Aug 17 '10 #4

100+
P: 1,059
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
Expand|Select|Wrap|Line Numbers
  1. <form action="x.php" method=GET>
  2. <input type=checkbox name=c1>
  3. <input type=checkbox name=c2>
  4. <input type=checkbox name=c3>
  5. <input type=submit name=submit>
  6. </form>
  7.  
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

Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['c1'])==true)
  2. {
  3. //  ...............
  4. //  do your task
  5. }
  6. if(isset($_GET['c2'])==true)
  7. {
  8. //  ...............
  9. //  do your task
  10. }
  11. if(isset($_GET['c3'])==true)
  12. {
  13. //  ...............
  14. //  do your task
  15. }
  16.  
Even though I must say, you question is not clear. I guess you are not clear with your need.
Aug 17 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.