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

Open browser page depending on XML results
Hello,

I have some PHP code that sends webbased from data to an external url ( in the form of

Time-based image rotation script
I'm trying to write a PHP script that rotates an image based on what time of day it is. I want the

MII Netweaver Server stopped due to CPIC connection Problem
Dear Experts,
We have SAP XMII 12.0 setup running on Netweaver 2004s,7.0, Java Stack only.

Count
Getting the same count everytime

Code:
$visitquery = mysql_query("SELECT COUNT(*) FR

phpmailer class & pop.gmail.com?
Code: <?php
$mail->IsSMTP();
$mail->Host = "pop.gmail.com";

ImageCreate()
When I create an image and add text to it I want my text to be replaced with a PNG image, because th

using variables in another page
I have a test database set up on localhost. I have a form that I can type a name into, hit the butto

post to self
Trying to get my form to submit to itself. However I am also trying to use an image for my submit bu

multiple recipients + dbuser mail recall
Hello,

I am building a php login script.

When the user registers the script will send

Anti Spam Code Problems
Ok where do i start? Probably by telling you I have very little working knowledge of PHP and that I

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