我想用选中状态的复选框更新数据库。
- 如果选中,则使用 1 更新数据库。
- 否则,如果未选中,则将其更新为 0。
它工作正常,但如果不选中它就不起作用。
<?php
include('lib/db.php');
$facebook_id ="10001088";
$query1 = "SELECT `video`,`quran`,`medical`,`groups` FROM `man_facebook`.`users` WHERE `facebook_id`='$facebook_id'";
$result1 = mysql_query($query1);
while($result = mysql_fetch_array($result1))
{
$video = $result['video'];
$quran = $result['quran'];
$medical = $result['medical'];
$groups = $result['groups'];
echo $video;
// echo $quran;
?>
<form method="post" action="<? echo $_SERVER['REQUEST_URI']; ?>" >
<input type="checkbox" name="video" id="video" value="<?echo $video;?>" <?php
if($video == '1'){
echo "checked='checked'";
}
else {}
echo "/>"
?>
<input type="submit" name="submit" value="Submit">
</form>
<?php
}
if (isset($_POST['submit']))
{
if (is_numeric($_POST['video']) && $_POST['video'] <2 )
{
$video1 = isset($_POST['video']) ? '1' : '0';
echo $video1;
$query = mysql_query("UPDATE `man_facebook`.`users`
SET `video` ='$video1'
WHERE `facebook_id`='$facebook_id'");
$video = $video1;
echo '<meta http-equiv="refresh" content="0" />';
}
}
//echo $query;
//header("Location: updatesql.php");
?>
我也可以使用jquery顺利更新吗?