473,587 Members | 2,448 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 1852
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
2079
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" CONTENT="text/html; charset=UTF-8">. I have the following problem: - I trie to do a query using ODBC (version 3.525.1022.0) and SQL
5
2426
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 somebody enters part_no, than using Javascript is it possible to connect to the part master and retrieve the division and desc information? I am not...
1
1650
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 store this phone number. Is it possible to query personalization data so I will be able to retrieve the phone number of each user?
1
1461
by: kalaisuresh | last post by:
using Two dimensional array how to retrieve the checkbox name in java script
1
1536
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 t1,t2,t3,t4 where f4='A' can anyone help me in this regd?
1
2083
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 is checkbox1.checked=convert.toboolean(ds.tables.rows); if i m using a flag variable bool a= convert.toboolean(ds.tables.rows); if(a==true)...
11
2638
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 foreign key. When I will add a new CD, the user interface for user will show combo box to choose the category from combo box and the selected value should...
3
3108
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 a database for some telephone interviews we are conducting. I want to query the database for those folks who have completed the interviews, in order...
1
3917
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 using "value" attribute.see for sample <input type="text" name="lastName" maxlength="50" size="20" value="<% If (Request("visitationID") <> "")...
12
77966
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 give me some idea where I am going wrong ?? I just want to retrieve data from my emp_mstr table and display it using my JSP file... The table...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3844
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1454
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.