Checkbox - showing original values for update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

Checkbox - showing original values for update

Post by jarow »

I have an update form which displays the orginal values of the record being updated, i.e. it displays all the TEXT fields. I cannot get it to disply the original values of the checkboxes - either checked or unchecked.

I have looked around in the forums but can't find an answer. This one seems the most promising but can't get it to work.

Code: Select all

$checked=$row_rsupdate2['checkbox'];
echo "<input type='checkbox' name='AN'";
if ($checked==1){ 
echo " CHECKED>"; 
}else{ 
echo ">"; 
} ?>


The checkbox values in my database are 1 or 0. The value of the checkboxes on the original add record form was "checkbox"

any ideas on how I might show the original checkbox values on the update form?

many thanks

Jim
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you're sure $row_rsupdate2['checkbox'] exists and contains what you expect. Try a little debug code in there.

Code: Select all

$checked=$row_rsupdate2['checkbox'];
echo "<input type='checkbox' name='AN'";
if ($checked=='1'){
	echo " CHECKED />";
}elseif ($checked=='0'){
	echo ">";
}else{
	echo ' disabled="true" />';
}
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

Post by jarow »

Thanks volka...you were right...checkbox didn't exist...I have now corrected it and it work fine...
Post Reply