473,513 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

4 New Member
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
4 1850
johny10151981
1,059 Top Contributor
your question is not clear enough, you didnt describe what are you trying to achieve.
Aug 16 '10 #2
dlite922
1,584 Recognized Expert Top Contributor
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
micropos
4 New Member
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
johny10151981
1,059 Top Contributor
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

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

Similar topics

0
2074
by: Miki | last post by:
Hi. I have a IIS server with php3 installed. I have SQL server database and data stored in unicode format (nvarchar fields). In header of my php I have the meta: <meta HTTP-EQUIV="content-type"...
5
2419
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
1
1647
by: Ya Ya | last post by:
I am using the personalization feature in asp.net 2.0 I am storing the phone number for each user. When a certain user enters his phone number I would like to check if another user already...
1
1455
by: kalaisuresh | last post by:
using Two dimensional array how to retrieve the checkbox name in java script
1
1531
by: kmanjani | last post by:
hi, i have to retrieve data from 4 tables at a time...can anyone guide me in wrting a query for the same.. Ex:- i have four fields f1,f2,f3,f4 which i need to retrieve from four tables...
1
2079
by: sonalpathak | last post by:
hi i m working on windows application using c#. i have to retrieve data from database in checkbox control but its giving the following error---cannot convert object to bool. the code i am typing...
11
2621
by: AishaKhalfan | last post by:
Hi all, I have to populate combo box that retrieve data from database in windows based application. I have two tables which are type and CD. Type has type ID and Category. CD has type ID as...
3
3101
by: billyqgoat | last post by:
Hi everyone - I apologize in advance, as a similar question has a discussion here, but I'm not exactly sure where to put the code, if it indeed requires code as it did in the older post. I have...
1
3905
by: gudipati | last post by:
hi,i have one problem.actually we can retrieve data from access. what is my requirement is when i retrieve data from access i want to store in text areas. finely,we can store if they r textboxes...
12
77932
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.