dsn46282 2019-02-15 12:39
浏览 39

如何从不同的无线电输出中检索输入字段数据

I want to create a customized registration form for customers and suppliers and I want to take data according to this. I created two radio buttons that display different fields depending on the selection. I managed to retrieve the data displayed at the push of the first button, but I do not manage to take over those in the secon one.

I already created two isset functions that i initialized differently but when I press the register in the second set of fields it returns to the main page


JS Code //displays content according to the selected button

window.onload = function() {
document.getElementById('ifYes').style.display = '';
document.getElementById('ifNo').style.display = 'none';
}
function yesnoCheck() {
if (document.getElementById('yesCheck').checked) {
document.getElementById('ifYes').style.display = 'block';
document.getElementById('ifNo').style.display = 'none';
}else if(document.getElementById('noCheck').checked) {
document.getElementById('ifNo').style.display = 'block';
document.getElementById('ifYes').style.display = 'none';
}}


HTML Forms //------

<form class="form-signup" action="includes/signup.inc.php" method="post">
<fieldset>
<input class="radio" type="radio" name="client" id="yesCheck"  onclick="javascript:yesnoCheck();" checked>Radio 1
<input class="radio" type="radio" name="client" id="noCheck"  onclick="javascript:yesnoCheck();">Radio 2

<div id="ifYes">
<input id="input" type="text" name="uid" placeholder="Username" value="<?php if (isset($_GET['uid'])) { echo $_GET['uid'];} ?>">
<input id="input" type="text" name="mail" placeholder="E-mail" value="<?php if (isset($_GET['mail'])) { echo $_GET['mail'];} ?>">
<input id="input" type="password" name="pwd" placeholder="Password">
<input id="input" type="password" name="pwd-repeat" placeholder="Repeat password">
<button type="submit" name="user-signup-submit">SIGNUP</button>
</div>

<div id="ifNo" style="display:none;">
<input id="input" type="text" name="firma" placeholder="Firma">
<input id="input" type="text" name="username" placeholder="Username" value="">
<input id="input" type="text" name="email" placeholder="E-mail" value="">
<input id="input" type="password" name="password" placeholder="Password">
<input id="input" type="password" name="password-repeat" placeholder="Repeat password">
<button type="submit" name="furnizor-signup-submit">REGISTER</button>
</div>
</fieldset>
</form>

PHP Code //// For client

if (isset($_POST['user-signup-submit']))
    {
    require 'dbh.inc.php';

    $role = '1';
    $username = $_POST['uid'];
    $email = $_POST['mail'];
    $password = $_POST['pwd'];
    $passwordRepeat = $_POST['pwd-repeat'];
    $sql = "INSERT INTO users (uidRole, uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?, ?)";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql))
        {
        header("Location: ../signup.php?error=sqlerror");
        exit();
        }
      else
        {
        $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
        mysqli_stmt_bind_param($stmt, "ssss", $role, $username, $email, $hashedPwd);
        mysqli_stmt_execute($stmt);
        }
    }

PHP Code //// For supplier

if (isset($_POST['user-signup-submit']))
    {
    require 'dbh.inc.php';

    $role = '1';
    $username = $_POST['uid'];
    $email = $_POST['mail'];
    $password = $_POST['pwd'];
    $passwordRepeat = $_POST['pwd-repeat'];
    $sql = "INSERT INTO users (uidRole, uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?, ?)";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql))
        {
        header("Location: ../signup.php?error=sqlerror");
        exit();
        }
      else
        {
        $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
        mysqli_stmt_bind_param($stmt, "ssss", $role, $username, $email, $hashedPwd);
        mysqli_stmt_execute($stmt)
        if (isset($_POST['furnizor-signup-submit']))
            {
            require 'dbh.inc.php';

            $role = '2';
            $firma = $_POST['firma'];
            $username = $_POST['username'];
            $email = $_POST['email'];
            $password = $_POST['password'];
            $passwordRepeat = $_POST['password-repeat'];
            $sql = "INSERT INTO users (uidRole, uidFirma, uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?, ?, ?)";
            $stmt = mysqli_stmt_init($conn);
            if (!mysqli_stmt_prepare($stmt, $sql))
                {
                header("Location: ../signup.php?error=sqlerror");
                exit();
                }
              else
                {
                $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
                mysqli_stmt_bind_param($stmt, "sssss", $role, $firma, $username, $email, $hashedPwd);
                mysqli_stmt_execute($stmt);
                }
            };
        }
    }

I want to insert the fields from both forms into the database, but I can only take those in the first form where Radio 1 is checked

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c