473,473 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to check if check box is clicked and send info to mySQL?

ilya Kraft
134 New Member
Hi,

I just started using check boxes to send information to mySQL. What I want to do is to send id of the user and article to database when check box is clicked and when it is un-clicked remove that information from database.

Right now I am at this stage

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. if (isset(//if user is logged in)) { 
  5. $addFavorite = '<input type="checkbox" id="favoriteIt" name="favoriteIt" />'; }
  6. else {
  7. $addFavorite = ""; }
  8.  
  9.  
  10. $asrticleDisplaylist = '<div>'.$addFavorite.'</div>';
  11. ?> 
  12.  
  13.  
So right now I display the check box for logged in user
on every article that is on the page.
What I want to do next is to somehow collect information from that check box, I assume that I will need to place check box inside <form method="post"> , but is it necessarily or can I somehow set method to post in the <input>?

After that I will need to find out if check box is checked or not. So I can than update information. I don't think I understand code behind this part, but I know what I need could be explained like this (I will write //comments in parts that I don't understand) :

Expand|Select|Wrap|Line Numbers
  1.  
  2. if //check box is clicked
  3.  
  4. $sql =  mysql_query("INSERT INTO favorites (article_id, user_id) VALUES ($article_id, $user_id)");
  5.  
  6. else
  7.  
  8. if //check box is not checked
  9.  
  10. //Delete stuff from database 
  11.  
  12.  
I don't know if it matters, but just in case I am using several check boxes on one page.

Thank You
Aug 15 '11 #1
3 1823
dlite922
1,584 Recognized Expert Top Contributor
You must have a <form>

the value="" attribute in the checkbox will be sent via whatever your form method is (post or get)

example: <input type="checkbox" name="foo" value="bar" />.

You can get this value by $_REQUEST['foo'].

If the checkbox wasn't check, then isset($_REQUEST['foo']) will return false.

Before putting this value in a MySQL database, clean it using mysql_real_escape_string() function to prevent hacking.


Good luck,


Dan
Aug 15 '11 #2
ilya Kraft
134 New Member
Soo

Expand|Select|Wrap|Line Numbers
  1.  
  2. mysql_real_escape_string($_REQUEST['foo'])
  3.  
  4. if isset($_REQUEST['foo']) {
  5.  
  6. $sql = mysql_query("INSERT INTO Favorites (article_id, user_id) VALUES ($article_id, $user_id)");
  7.  
  8. }
  9.  
  10.  
Will this do the job?

Thnx
Aug 15 '11 #3
Dormilich
8,658 Recognized Expert Moderator Expert
You can get this value by $_REQUEST['foo'].
bear in mind that GET data overwrite POST data. and changing the action value is nothing complicated.
Aug 16 '11 #4

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

Similar topics

0
by: R A | last post by:
Hi I have two applications, one is Windows Service and the other is Windows application. How can I send data between this two applications? I would prefer not to use delegates but something else...
1
by: Chris | last post by:
Hi, how can I send information that is in the Response.OutputStream to the client but continue server processing without having to close the page , or without having to Reponse.End() the...
1
by: chuckdfoster | last post by:
How do you send info from popup window to a parent? From the parent, the user click a link and a popup window appears with a calendar in it. I want them to click the date in the popup and...
2
by: Steve JORDI | last post by:
Hi, I'm having a little trouble trying to update a page content when the user clicks a check box. Basically, I need to reload a page to update its content depending on that checkbox status. I...
2
by: an96su | last post by:
Hi, I'm new to php. i'm trying to send information from my php (client) script to a website that is running javascript. Here is an extract of the server's response to my initial http request. ...
2
by: kenno69 | last post by:
Well its a registry form and i want them post there info then when they press submit it will show them there name, email and all that stuff, then i wanted to know if it is possible to submit the same...
3
by: Zabooster | last post by:
Hi all, I have to submit a project in 2 days' time and am currently challenged trying to send information inputted into textboxes, radiobuttons and checkboxes present in different forms to a sigle...
3
by: Bam | last post by:
Hey gang. I have searched the web, and can't find what i need. hoping someone here can help i have a form that pops up based on a click. the popup opens up correctly. now what i want it to do is...
1
by: Carlos Paparoni | last post by:
Hi everyone, I came across this site and thought it would be a good place to ask. Hope anyone can help. Here is the use case: I have n domains, each hosted separately. Lets call them domain A, B,...
0
amit sabal
by: amit sabal | last post by:
Hi, i m working on the code to send an email the selected record of the mysql database thru html page. all the records can be viewed on the thru select query ant after selecting the required check...
0
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,...
0
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
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
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,...
1
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.