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