gpt4 book ai didi

php 单选值不会更新列

转载 作者:行者123 更新时间:2023-11-28 23:55:37 24 4
gpt4 key购买 nike

我正在编写一个 php 函数来更新 mysql 记录除了单选按钮值之外的所有更新都完美我什至尝试打印 radio 值以检查 radio 是否工作并且我得到了成功的结果但是问题仍然存在我无法在我的 SQL 中更新 radio 值

这里要提到的重要一点是“ radio 值是整数 1、2、3 等”

这是我的html代码

        <input type="radio" name="active_status" id="radio1" class="we-radio" value="1">
<label for="radio1" class="we-label">Active</label>

<input type="radio" name="active_status" id="radio2" class="we-radio" value="0">
<label for="radio2" class="we-label">Inactive</label>

<input type="radio" name="featured_status" id="radio3" class="we-radio" value="1">
<label for="radio3" class="we-label">Featured</label>

<input type="radio" name="featured_status" id="radio4" class="we-radio" value="0">
<label for="radio4" class="we-label">Normal Video</label>

及其我的 php 代码

    $activation_vid = $_POST['active_status'];
$featured_vid = $_POST['featured_status'];

$updates = array();
if (!empty($activation_vid))
$updates[] = '`vid_act_stat` ="'.mysqli_real_escape_string($conn,$activation_vid).'"';
if (!empty($featured_vid))
$updates[] = '`vid_featured_stat` ="'.mysqli_real_escape_string($conn,$featured_vid).'"';

$updates = implode(', ', $updates);
$sql = "UPDATE `tblmevids` SET $updates WHERE vid_id = '$vid_edit_id'";
$result=mysqli_query($conn,$sql);
if($result){
$sucess = "<div class='success'>Perfect!!! Vid has been updated: ".$current_vid_code."</div>";
} else {
$error_display = "<div class='errormsgbox'>An error occured. Please Try Again</div>";
}

最佳答案

当您选择 Inactive Status 时,您在 POST 中传递了 0 值并且您正在使用空函数来检查导致问题的原因。因此,只有当您选择事件状态时,您的查询才会将其更新为非事件状态,条件将失败而不是使用空

 if (!empty($activation_vid))

使用

isset() and is_numeric()

来自 PHP 手册 http://php.net/manual/en/function.empty.php

The following things are considered to be empty:

"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
$var; (a variable declared, but without a value)

它对我有用试试这个

$activation_vid = '0';
$featured_vid = '1';
$vid_edit_id=5;
$updates = array();
if (is_numeric($activation_vid) and isset($activation_vid))
$updates[] = '`vid_act_stat` ="'.$activation_vid.'"';
if (is_numeric($featured_vid) and isset($featured_vid))
$updates[] = '`vid_featured_stat` ="'.$featured_vid.'"';

$updates = implode(', ', $updates);
$sql = "UPDATE `tblmevids` SET $updates WHERE vid_id = '$vid_edit_id'";
print_r($sql);
...
//rest of your code

关于php 单选值不会更新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31772784/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com