Php 单选按钮值始终设置为“;在”;

Php 单选按钮值始终设置为“;在”;,php,mysql,radio-button,Php,Mysql,Radio Button,我的表单中有以下字段: <div class="col-12"> <label>Esti de acord cu procesarea datelor tale conform celor de mai sus?</label> <div class="form-check"> <input

我的表单中有以下字段:

            <div class="col-12">
              <label>Esti de acord cu procesarea datelor tale conform celor de mai sus?</label>
              <div class="form-check">
                <input class="form-check-input" type="radio" name="gdpr" id="gdpr1" value="Da, sunt de acord">
                <label class="form-check-label" for="gdpr1"> Da, sunt de acord</label>
              </div>
              <div class="form-check">
                <input class="form-check-input" type="radio" name="gdpr" id="gdpr2" value="Nu, nu sunt de acord"/>
                <label class="form-check-label" for="gdpr2"> Nu, nu sunt de acord</label>
              </div>
            </div>
然后转到函数createClient,如下所示:

  createClient($conn, $date, $name, $birthdate, $locality, $phone, $mail, $treatments, $gdpr);
数据库看起来像这样:

另外,无论我选择什么选项,它仍然会在数据库中插入“on”作为一个值

希望这能更好地解释

乐:

以下是createClient函数:

function createClient ($conn, $date, $name, $birthdate, $locality, $phone, $mail, $gdpr) {
    $sql = "INSERT INTO clients (clientsDate, clientsName, clientsBirthdate, clientsLocality, clientsPhone, clientsEmail, clientsGDPR) VALUES (?, ?, ?, ?, ?, ?, ?);";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        header("location: ../clients?error=stmtfailed");
        exit();
    }

    mysqli_stmt_bind_param($stmt, "sssssss", $date, $name, $birthdate, $locality, $phone, $mail, $gdpr);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_close($stmt);
}

在您添加的代码中,有一个错误:函数签名与函数调用不对应


您使用9个参数调用
createClient
,而定义使用8个参数。可能变量
$treatments
的值为“on”?因为函数实现中的
$gdpr
值是调用函数时变量
$treatments
中的值。显然,我留下了另一个变量,它取了这个变量的值。非常感谢各位Andrei Valentin Niculae 3小时前

欢迎来到Stack Overflow。我建议阅读一些关于问题应该包括哪些内容的建议。目前,我们没有足够的信息来确定问题。有两件事你应该澄清:1)“on”对你意味着什么(是肯定值,“Da”?)和2)共享你处理此表单提交的代码。学习“现在关于PHP部分,在这里”——在哪里?请不要在评论中发布扩展代码,编辑您的问题并将其包含在评论中(格式正确)。您需要显示
createClient
函数,因为这是一个实际的数据库操作。编辑了帖子并添加了函数。这已经解决了。问题的原因是$treatments变量的传递?是的,这就是罪魁祸首。很高兴你找到了它。所以,当我在你的“解决通知”前抓住罪犯时,你能不能把我的回答设为被接受的答案
function createClient ($conn, $date, $name, $birthdate, $locality, $phone, $mail, $gdpr) {
    $sql = "INSERT INTO clients (clientsDate, clientsName, clientsBirthdate, clientsLocality, clientsPhone, clientsEmail, clientsGDPR) VALUES (?, ?, ?, ?, ?, ?, ?);";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        header("location: ../clients?error=stmtfailed");
        exit();
    }

    mysqli_stmt_bind_param($stmt, "sssssss", $date, $name, $birthdate, $locality, $phone, $mail, $gdpr);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_close($stmt);
}