Limiting checkboxes?


Posted on 16th Feb 2014 07:03 pm by admin

Hi guys,

I have this code: Code: if(isset($_POST['selected'])) {
foreach($_POST['selected'] as $item) {
Did you know?Explore Trending and Topic pages for more stories like this.
$sql = "SELECT * FROM tablename WHERE ID=$item";
mysql_query($sql) or trigger_error("SQL: $sql, ERROR: " . mysql_error(), E_USER_ERROR);
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if ($num_rows>6) {
echo ("Too many checkboxes were selected");
}
else

while ($db_field = mysql_fetch_assoc($result)) {

echo "stuff that is ok if number of checkboxes is correct";
}
}
}

I am trying to limit the number of checkboxes that were selected, to say a max of 6. If the user selected any more than 6 a message should appear saying too many checkboxes were selected.

Can anyone see where i went wrong?

Cheers for any help fellas...
No comments posted yet

Your Answer:

Login to answer
191 Like 41 Dislike
Previous forums Next forums
Other forums

FlashVar function how to insert variables
Hi guys. Im new in this forum and also new in php programming. Can you help me about this code?
<

Include ("Absolute Path") of a file?
I'm not sure what I'm doing wrong. I am writing my php code in the same directory of the file that

IDOC error
Hi, When i send IDOC from ECC system to MII there is no problem ECC side, i says message sent succe

IMAGE - SERVER SIDE scripting help...
How to receive pixel data of an image and buid a bitmap file on the server using the HTTP POST metho

How to give the privillege for triggers?
Hi,

How to give the privillage for triggers to particular user?

Please let me

reading partial code from external site
Hi,

I am trying to write a script for my website to get an article from an external website.

dinamic "textboxes"?
Ey all, my first post here, i hope its not a hard one

I display mysql results in a table

simple ping code
been searchin the site/web and found code thats simple but doesnt work.

I have a personal we

Need help with an email blocker for a guessbook
I am new with php and here is a simple guessbook page but I am being hit with spam from a group of t

Changing files over
Just thought I'd start with the new forums looking really nice .

Ok basically I've made this

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash