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
- <?php
- if (isset(//if user is logged in)) {
- $addFavorite = '<input type="checkbox" id="favoriteIt" name="favoriteIt" />'; }
- else {
- $addFavorite = ""; }
- $asrticleDisplaylist = '<div>'.$addFavorite.'</div>';
- ?>
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
- if //check box is clicked
- $sql = mysql_query("INSERT INTO favorites (article_id, user_id) VALUES ($article_id, $user_id)");
- else
- if //check box is not checked
- //Delete stuff from database
Thank You