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>