i want to update a form and i hav used 1 checkbox
when i check da checkbox the value in table shd be 1 and if unchecked then the value should be zero
now when i update the form then the checkbox has to be checked if previously it was checked and vice versa..
but its not...
here's the code:
for inserting values:
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die("could not connect:".mysql_error());
}
mysql_select_db("db1",$con);
if(isset($_POST['submit']))
{
$x=$_POST['a'];
$y=$_POST['b'];
$z=$_POST['c'];
$u=$_POST['d'];
mysql_query("INSERT INTO data(name,class,rollno,value) VALUES('$x','$y','$z','$u')");
}
?>
<html>
<body>
<form method="post">
name:<input type="text" name="a"><br />
class :<input type="text" name="b"><br />
rollno:<input type="text" name="c"><br />
value:<input type="checkbox" name="d" value="1"><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
$sql="SELECT * from data";
$result=mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>name</th>
<th>class</th>
<th>rollno</th>
<th>value</th>
<th>edit</th>
<th>delete</th>
</tr>";
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['id'] ."</td>";
echo "<td>".$row['name'] ."</td>";
echo "<td>".$row['class']."</td>";
echo "<td>".$row['rollno']."</td>";
echo "<td>".$row['value']."</td>";
?>
<td><a href="updatee.php?id=<?php echo $row['id'];?>">edit</a></td>
<?php
echo "</tr>";
}
echo "</table>";
mysql_query($sql,$con);
mysql_close($con);
?>
for updating form:
<?php
$id=$_GET['id'];
$con=mysql_connect("localhost","root","");
if(!$con)
{
die("could not connect".mysql_error());
}
mysql_select_db("db1",$con);
$result=mysql_query("SELECT * from data WHERE id='$id'");
while($row=mysql_fetch_array($result))
{
$x=$row['name'];
$y=$row['class'];
$z=$row['rollno'];
$u=$row['value'];
}
if(isset($_POST['submit']))
{
$x=$_POST['a'];
$y=$_POST['b'];
$z=$_POST['c'];
$u=$_POST['d'];
mysql_query("UPDATE data SET name='$x',class='$y',rollno='$z',value='$u' WHERE id='$id'");
header("location:insert.php");
}
?>
<html>
<body>
<form method="post">
name:<input type="text" name="a" value="<?php echo $x;?>"><br />
class :<input type="text" name="b" value="<?php echo $y;?>"><br />
rollno:<input type="text" name="c" value="<?php echo $z;?>"><br />
value:<input type="checkbox" name="d" value="<?
if ($u==1)
{
echo '$d="checked"';
}
else
{
echo '$d="uncheck"';
}
?>"><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>