View Full Version : Checkboxes in php
I try to determine if a variable is set and if so then the checkbox is selected. I tried it with this code but it dont works, when i execute it then all the checkboxes are checked while only one field is filled with aw so 1 checkbox has 2 be checked instead of all :(
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
As you can c, i'm using this code to check if its set or not:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Hope someone can help me out, any help is appreciated.
i've laready asked 5 times for this :( looks like we'll have to wait to v 3 to me :(
Try this...
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Thanks for the replies
@firefly, that didnt worked. I tried this code and it works now :up:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Now i'm almost done with the hack but i'm stuck when you uncheck a checkbox, then the row wont be updated. The variable is still in the database. Lets say i have a award called lesane and it has currently the variable 1 in the database, now i want to uncheck it and when i click on submit then lesane must be updated as empty. Hope u can follow me and can help me out with this
You need to set a hidden field saying the field WAS there, and then in the parsing if the variable doesn't exists (=checkbox is not checked) remove the row.
Cool, thanks Firefly. I gonna test that out.
Be Right Back :D
i'm going crazy :D
i'm using the following code:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
I have currently 2 awards in the database
1. Awards name with the awardsid 9 and aw is also 9
2. Lesane with the awardsid 13 and aw is empty (means not checked)
So when i execute the script then i c awards name selected and lesane is not selected and if i check the code by <input type =hidden then i c:
<input type='hidden' name='delete[]' value='aw[13]'>
so thats right, lesane is not selected and have the id 13.
Now i'm totally confused because when i click on submit then it deletes lesane totally and when i uncheck the award with the name "awards name" then that aw is not gonna deleted because only the input type = hidden was lesane :(
So my questions are:
Whats the delete query to delete only the aw row from awards where awardsid=?
&
How is it possible to delete the aw row from the award called "Awards Name" when i uncheck him?
I hope u have a solution :(
badr511
06 Feb 2002, 10:51
working now or not
badr511
06 Feb 2002, 11:07
firefly why ican't download attachment
No, its still not working.
When i try 2 unselect a checkbox and press on submit then he must delete the variable from that table :?:
Originally posted by FireFly
You need to set a hidden field saying the field WAS there, and then in the parsing if the variable doesn't exists (=checkbox is not checked) remove the row.
Firefly, could you give me an example?
Ok, just talking in general here, but you should get the point.
If you look in the hacks database (http://www.vbulletin.org/hacks/index.php?s=&action=showcat&catid=5) you will see something like this:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
So you can see I put two fields for each hack, one is a part of an array all[], which eventually has all the ID's of the hacks in that page. The value of that field is either 0 or 1. 1 if the user already installed the hack, and 0 if he hasn't.
Then there's the real checkbox, that the user can change. That's part of the install[] array, which holds all the ID's of the hacks the user WANTS to have installed.
And here's a little bit of code from the page itself, that parses the results:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
I'm listing the stuff from the all[] array, that has the ID's of the hacks and the state (installed or not) BEFORE the submit, and put the 1/0 into $was (meaning what WAS the state). Then I'm taking the value of the install[] with the current ID and put it into $now (which represents the state as it NEEDS to be).
And then it's really simple logic! If the hack wasn't installed ($was equals 0) and it SHOULD be now ($now equals yes), then we need to install the hack.
Otherwise, if the hack WAS installed ($was is 1) but the user un-checked the box (so $now is not yes), we need to un-install the hack.
If non of the above is true, it means that the hack is either already installed and the user didn't touch the checbox, or it is not installed but the user didn't check the checkbox neither.
*takes a deep breath* :)
Did I say I was talking in general? :D
Thanks Firefly, it works almost 100%.
However one thing: $threadid. Where and how did u defined that one because i get an error:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
I'm not using $threadid but $award[awardsid] for the id.
This is my currently code:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Its a little general ;):D
1. What's this $kol crap? The checkbox value is always yes!
2. The whole part where you list the array and do your stuff is AFTER you SUBMIT the form, not while printing it.
1.
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
So kol is yes when the checkbox has a variable.
2. I'm listing the stuff from the all[] array, that has the ID's of the hacks and the state (installed or not) BEFORE the submit
So i thought before the submit :D
Its working perfect now, thank you for your help Firefly. Appreciated.
Originally posted by FireFly
1. What's this $kol crap? The checkbox value is always yes!
You right, its always yes :surprised :stoned:
How did you defined the value yes?
firefly, it works perfect if i have just 1 award but when i have more then 1 award then it updates the database only with the last award, it only listening to the last award. So if i have 2 awards then it updates only the 2nd award and ignores the 1st one. Could u help me with this (hopefully) last problem ;)
I have the currently code:
Code before submit:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Code after submit:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Nevermind, i got it working now :up: :)
vBulletin® v3.6.12, Copyright ©2000-2013, Jelsoft Enterprises Ltd.