0
I have the table "Cd_comments" in the mysql database, with the column "comment_id" "user_id" "text" and "anonymity" I want to make a system for a website, where the user will comment, and if he has marked the checkbox "send anonymously?" it sends the value "1" to the column "anonimo" of the table "comments" and if nothing is marked it sends the value "0"
I am using the following input for the checkbox
<input type="hidden" name="anony" id="caixa-disabled" value="0" <?php echo ($cd['comentarios']['anononimo'] == 0) ? 'checked': '';?>>
<input type="checkbox" name="anony" id="caixa-enabled" value="1" <?php echo ($cd['comentarios']['anononimo'] == 1) ? 'checked': '';?>>
But mark or not mark, no value is sent to the database.
I don’t use pure html, so I can do the logical and visual part all together, since it’s a simple form, on a site that only has one page. Should I use echo? Post? Something needs to be done in jquery to make it work or only PHP can solve the problem.
Sorry, I study programming very little time (less than 1 month to be more exact) and I’m lost
Friend, post the code of how you are receiving this data and entering in the bank.
– Jorge.M
Should I edit my question? Because that’s exactly what it’s about: How to get the value of the checkbox entered into the database.
– jonatas Borges
By default unmarked checkboxes are not sent by the form... just check if the variable exists and the value is 1, if there is simply grave false in the database
– edson alves
I really appreciate your help, but this is exactly what I have no idea how to do. I don’t know if this is done with PHP, with jquery, or with q, I was webdesign and only worked with HTML, without database. Today I study programming and I’m learning about databases, but I still don’t know how to take the data entered in a form or something like that to a database, and what to use for that. PHP? Jquery? Both? The logical part of the programming "if, Else, if Else" is blz, but do Posts, Gets, Selects, which may be my Balance heel in this less than 1 month of programming
– jonatas Borges
If it’s just a checkbox, it’s enough:
$marcado = isset($_POST['name']);
"name" is the name you put in the checkbox. If there are several, generate the name of each one with the ID together– Bacco
Thanks Bacco, now I have placed myself better knowing that the "name" is the name of the checkbox. I just have a question, the marked $I will use in the checkbox input in html?
– jonatas Borges
You can use for example
<input type="checkbox" value="1" name="anonimo"<?=$is_anon?' checked':''?>>
so if$is_anon
is true the string will be includedchecked
(note that you have to leave 1 blank space at the beginning checked) - If it is false will be worth the''
empty string.– Bacco
Ai you get your checkboxes like this, for example
$is_anon = isset($_POST['anonimo']);
$is_news = isset($_POST['newsletter']);
and so on, giving different names to each one, so that you know which is which (I used different names in the PHP variable and in the "name" of HTML for you to see which is which) - remembering that is still$_POST
if it’s<form method="post"
, otherwise it is$_GET
– Bacco
To save in DB can use something like this:
$campo_anon=$is_anon?'1':'0';
thus$campo_anon
will be1
or0
. (the same applies if you wantsim
andnão
, just replace 1 and 0)– Bacco