Advertisement

11.03.2006 at 12:29PM PST, ID: 22048479
[x]
Attachment Details

Trouble with checkboxes and php forms

Asked by DVation191 in PHP and Databases

Tags: array, checkbox, tables

I have a form on one page (kb.php) that posts to another page (kbedit.php) and it's designed to update a table in mysql. This is what the form looks like (from page source after being processed by php on the server):

<form action="kbedit.phpp" method="post" class="formstyle">
<table width='700' border='0' cellpadding='1'>
<tr><td><input type='text' name='priority[]' value='40'></td><td><input type='checkbox' name='featured[]' checked='checked' /></div></td><td><a href='http://www.awebsite.com' target='_blank'>Sample  Link</a></td></tr><tr><td><input type='text' name='priority[]' value='40' /></td><td><input type='checkbox' name='featured[]'  /></td><td><a href='http://www.anotherwebsite.com/' target='_blank'>Sample  Link</a></td></tr></table><br><input type='Submit' name='Submit' value='Submit'></form>
(I removed some non-essential tags)

The kbedit.php code that processes the post data looks like this (pardon the bad code, I'm new to php):
$i = 0;
$arrayid = 1;
while ($row = mysql_fetch_array($result1))
{
      $featured_holder = "on";
      if(!strcmp($featured[$i],$featured_holder)){
      $featured_result = '1';
      }
      if (!isset ($featured[$i])) {
      $featured_result = '0';
      }

mysql_query("UPDATE knowledgebase SET featured = '$featured_result', sequence = '$priority[$i]' WHERE knowledgebaseid = $arrayid") or die(mysql_error());

$arrayid++;
$i++;                  
}       


Now believe it or not, it seems to work perfectly when it comes to updating the sequence (priority). Anything I enter in the form gets processed okay and updated in the database. The problem I'm having is with the "featured" form element. I can check and uncheck the checkboxes in kb.php and it seems to update the database fine except for when i try to leave the first checkbox unchecked and the second one checked. When I do this is actually performs the reverse in the database...it will make featured knowledgebaseid 1 = 1 and featured knowledgebaseid 2 = 0. I can't find the error in my code that would make this happen. Can anyone clarify this for me? Start Free Trial
[+][-]11.03.2006 at 12:34PM PST, ID: 17869949

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 12:53PM PST, ID: 17870117

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 12:58PM PST, ID: 17870150

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:03PM PST, ID: 17870188

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:11PM PST, ID: 17870236

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:14PM PST, ID: 17870260

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:17PM PST, ID: 17870281

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:21PM PST, ID: 17870313

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:22PM PST, ID: 17870316

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:34PM PST, ID: 17870392

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:40PM PST, ID: 17870434

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:42PM PST, ID: 17870448

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:52PM PST, ID: 17870519

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 01:58PM PST, ID: 17870565

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 02:03PM PST, ID: 17870608

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 02:09PM PST, ID: 17870643

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 02:19PM PST, ID: 17870710

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Tags: array, checkbox, tables
Sign Up Now!
Solution Provided By: manav_mathur
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.03.2006 at 02:22PM PST, ID: 17870733

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 03:01PM PST, ID: 17870937

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 04:27PM PST, ID: 17871299

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11.03.2006 at 07:12PM PST, ID: 17871920

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 07:20PM PST, ID: 17871931

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.03.2006 at 07:46PM PST, ID: 17871972

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.06.2006 at 04:57AM PST, ID: 17880551

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32