我想为客户和供应商创建定制的注册表格,并据此获取数据。我创建了两个单选按钮,它们根据选择显示不同的字段。我设法检索了按第一个按钮时显示的数据,但没有设法接管secon中的数据。
我已经创建了两个isset函数,它们的初始化方式不同,但是当我在第二组字段中按下寄存器时,它将返回主页
JS代码//根据所选按钮显示内容
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表单// ------
<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代码////对于客户端
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代码////对于供应商
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);
}
};
}
}
我想将两种形式的字段都插入数据库,但是我只能采用选中了Radio 1的第一种形式。