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) {
$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

Why use OOP?
Can someone explain to me why I should use OOP instead of procedure based code.

Im building a

present value of sequence?
Hi

Please help me to find out the present value of sequence?

Thanks

IF STATEMENT HELP
Hi
i have created a calendar from a table:

Code: Calendar: October 2009
<table w

want to add a break after a certain amount of characters
i was wondering how to add a break in a blog post after a certain amount of characters... any idea o

Adding delete feature to my forum
Hello I am currently trying to add a delete feature to my forum. I believe I have everything built r

PHP Programming error. Please help!
Hi there,

Am making a website for a friend and have encountered a problem that i need fixing

Agency Business Process
Hi,

I don’t understand the process of the agency business in SAP.

In my

SOAP Issue
Hi,

I am facing some understanding problem with SOAP basic.kindly recommend some SOAP expert.

how do i make new line after *
First check this page here. and you see my report. Im pulling form a mysql db. I want to beable to m

$_GET problem
Hi all,

Have a bit of a problem with a little piece of code, I am not sure if this should be

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