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

Sorting JTable on more than just the values listed in the columns
I have a collection of objects that store (among other things) two integer values. I only want to di

adding up might be solved tell us cheers.
i think i finally solved this anybody.

last time i was getting the wrong results.

Code

PHP loop
Okay so I have several "articles" stored in a mysql database and am attempting to echo tho

please fix the error
What is the error in the below code ???
Line number On/Off | Expand/Contract <?php

Help Import Animoto and Youtube
CAn someone help me urgently want to allow users on my website to import youtube/revver/dailymotion

Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t

Help: problem with Headers to download PDF file
Hi,

I'm trying to implement a script where when a user clicks a link he gets a PDF file to op

using explode() to fill in checkboxes
Hi

I have a field stored in a table that contains regions in the UK separated by commas. Ther

INSERT data problem!
After having an string with apostrophes ', double quotes " or any other special characters, suc

parse error
On my local machine I keep getting parse error for my footer. When I put it online, it doesn't show

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