Checkbox not displaying or updating<

liunx

Guest
Hi, I have a page where a user enters an 'ID' clicks submit and a record is found. The user can then make changes to the record, click submit and the record updates.

The problem is the two checboxes; when the record is found the checkboxes do not display the checked value if that is the value ie no 'tick' when there should be a 'tick', even though the variable containing that value is '1'.

Also after updating, the value '1' isnt getting passed just the '0' value. Even when the value passed should be '1' it arrives at the next page as '0'. If the value to be passed is '0' then "" is passed.

Any help appreciated.

BobNZ


if (($row[7])==1){
$checkvalueA = "checked";
}
else {
$checkvalueA = "";
}
if (($row[15])== 1){
$checkvalueB = "checked";
}
else {
$checkvalueB = "";
}



<td><input type="checkbox" name= "Replace" value='<?php echo $row[15] ; ?>' $checkvalueB ></td>
<td>FDD</td>
<td><input type="checkbox" name= "FDD" value='<?php echo $row[7]; ?>' $checkvalueA ></td>

yes Scoutt we have been here before but I changed the code layout and now it doesn't work :mad:if you have a value in the checkbox other than 1 than that is the value that gets submitted, not the value 1 or 0

<input type="checkbox" name= "Replace" value='<?php echo $row[15] ; ?>'

that will submit the value of $row[15] if checked, if not checked it will submit nothing "NULL" or ""

the fact you are comparing what is in the database might be the problem. does it update the database correctly? because if it didn't then the value wouldn't be there.

how are you updating the database if the checkbox was checked?Whatever value is created when the user ticks the checkbox or doesn't tick the check box is passed to the update query
those values are then stored in the database as '1' for checked and '0' for unchecked. These values are then used as part of query to populate the update page pre update. But it isn't working!!! lol

BobNZ


if(!$WSID)
{
print "<H2 align=\"center\">You must enter a WSID.</H2>";
exit;
}
else
"AUTOCOMMIT=0";
begin();

$WSIDquery= "select * from tblWorkstation where WSID = '".$WSID."' FOR UPDATE";
$result = mysql_query($WSIDquery, $connection);

$UDquery= "UPDATE tblWorkstation set
WSID='".$_POST['WSID']."',
Make='".$_POST['WSMake']."',
ModelName='".$_POST['ModName']."',
ModelNumber='".$_POST['WSModelNum']."',
SerialNumber= '".$_POST['WSSerial']."',
CPU= '".$_POST['CPU']."',
HDD='".$_POST['HDD']."',
FDD='".$_POST['FDD']."',
MemoryMB= '".$_POST['Memory']."',
MacAddress='".$_POST['MacAdd']."',
NIC='".$_POST['NIC']."',
IPAddress='".$_POST['IPAdd']."',
RCCode= '".$_POST['RCCode']."',
OperatingSystem='".$_POST['OS']."',
Purchased='".$_POST['DatPurch']."',
Replaced= '".$_POST['Replaced']."',
PatchCordLengthmm= '".$_POST['PCordLen']."',
AssetID= '".$_POST['AssetID']."',
DateInstalled='".$_POST['DatInst']."',
DateEntered ='".$_POST['DatEnt']."',
Name='".$_POST['DataEnteredBy']."',
Comments='".$_POST['Comments']."',
Department='".$_POST['Dept']."',
Building='".$_POST['BuildName']."',
Level= '".$_POST['Level']."',
CommonUsers='".$_POST['CommonUsers']."',
Outlet='".$_POST['Outlet']."',
Situation='".$_POST['Situation']."'
where WSID='".$_POST['WSID']."'
";

$result = mysql_query($UDquery, $connection);actually no. if the checkbox is not checked it will be null or empty. the fact you get a zero is the default value mysql enters in NULL.

but yes it should work the same way.Yes, I follow that. But shouldnt the checkbox have a tick in it when the page populates from the query, if the value of $row[7] is '1'? The if statement catches the value of $row[7] and sets $checkvalue to the appropriate value so I cant see why the checkbox remains empty no matter what the value of $checkvalue. Do I have the syntax wrong?
Thanks for the reply.

BobNZ :confused:ok this what I'm trying now.

<td width="20">
<?php if ($row[7]=='0'){
print "<td><input type=\"checkbox\" name= \"FDD\" value= $row[7] ></td>";

}
else if($row[7]=='1'){
print "<td><input type=\"checkbox\" name= \"FDD\" value= $row[7] checked ></td>";

}
?>
when page is populated by the query checkbox shows a tick if value of $row[7]='1' or no tick if $row[7]='0' if tick is removed and page updated record shows updated value ie. $row[7]='0' however if original value is $row[7]='0' and a tick is put the checkbox and page updated then updated value does not show the change ie. $row[7] still = '0'
I'm checking $row[7] value at all stages during update the one thing that doesn't happen is when variable is posted if a tick has been put in the checkbox it still posts '0'.

I'm baffled any help appreciated.

BobNZif you check the box and then update and the value is still zero then you have something messed up either on the form or the update query. can I see some code for the whole thingok here goes.See next postsame as your last thread. you cannot use mysql_fetch_row. that retrieves only 1 row. you have to use mysql_fetch_array. so change all those and then change this

if ($HTTP_POST_VARS)

to read

if ($_POST['Submit2'])

also you have many things wrong with it. you don't even check for the the submitted value. you also don't update the database so nothing can change. I am sorry but after looking at the code on both pages I don't see what you are doing, they are both the samecode. plus you are using the wrong variable in that checkbox

<?php if ($row[7]=='0'){
print "<td><input type=\"checkbox\" name= \"FDD\" value= $row[7] ></td>";

according to where that is at in the code you should be using $Arow instead of $row.Sorry Scoutt I sent the same page twice, it was late :P
heres the right page.

BobNZthat makes better sense :)

$FDD=($_POST["FDD"]);

those are all wrong. surprised you don't get a parse error.

$FDD=$_POST["FDD"];

that is the way it is suppose to be. change all of them that are like that.

$UDquery= "UPDATE tblWorkstation set WSID='".$_POST['WSID']."',
where WSID='".$_POST['WSID']."'

you can't update a column name where you use it in the query. the variable never gets updated cause it changed. you do it in both updates.Thanks Scoutt, I have sorted the checkbox problem

in pg1 I added

<input type="checkbox" name="FDD" <?php if($row[7] == "1"){echo " CHECKED";}else {echo "";}?>>
<input type="checkbox" name="Replaced" <?php if($row[15] == "1"){echo " CHECKED";}else {echo "";}?>>


in pg2 I added

if ($FDD==on){
$FDD='1';
}
else{
$FDD='0';
}
if($Replaced==on){
$Replaced='1';
}
else{
$Replaced='0';
}


Now everything is working the way it should.
I see what you mean about the WSID have changed that.
Thanks again for the help
BobNZ
 
Back
Top