我创建了两个在单选按钮选择上显示的表单。我还在我的数据库中创建了两个不同的表,用于选择不同的单选按钮。
我想根据单选按钮选择将不同的表单存储到不同的表中。在选择“私人用户”时,我希望表格上输入的数据存储到tbl_users和选择“专业代理”,我希望表格上输入的数据存储到tbl_agents。
我试过这样做,但数据没有存储到表中。
有人知道怎么做吗?
问候,Asvp
这是我的代码:
function ShowHideDiv() {
var chkYes1 = document.getElementById("chkYes1");
var dvtext1 = document.getElementById("dvtext1");
var dvtext13 = document.getElementById("dvtext13");
var dvtext12 = document.getElementById("dvtext12");
var dvtext11 = document.getElementById("dvtext11");
var dvtext10 = document.getElementById("dvtext10");
var dvtext9 = document.getElementById("dvtext9");
var chkYes2 = document.getElementById("chkYes2");
var dvtext8 = document.getElementById("dvtext8");
var dvtext7 = document.getElementById("dvtext7");
var dvtext5 = document.getElementById("dvtext5");
var dvtext4 = document.getElementById("dvtext4");
var dvtext3 = document.getElementById("dvtext3");
var dvtext2 = document.getElementById("dvtext2");
var button = document.getElementById("button");
dvtext1.style.display = chkYes1.checked||chkYes2.checked ? "block" : "none";
dvtext9.style.display = chkYes1.checked||chkYes2.checked ? "block" : "none";
dvtext10.style.display = chkYes1.checked||chkYes2.checked ? "block" : "none";
dvtext11.style.display = chkYes1.checked||chkYes2.checked ? "block" : "none";
dvtext12.style.display = chkYes1.checked||chkYes2.checked ? "block" : "none";
dvtext13.style.display = chkYes1.checked||chkYes2.checked ? "block" : "none";
dvtext2.style.display = chkYes2.checked ? "block" : "none";
dvtext3.style.display = chkYes2.checked ? "block" : "none";
dvtext4.style.display = chkYes2.checked ? "block" : "none";
dvtext5.style.display = chkYes2.checked ? "block" : "none";
dvtext7.style.display = chkYes2.checked ? "block" : "none";
dvtext8.style.display = chkYes2.checked ? "block" : "none";
btn1.style.display = chkYes1.checked ? "block" : "none";
btn2.style.display = chkYes2.checked ? "block" : "none";
}
<?php
require('db.php');
// If form submitted, insert values into the database.
if (isset($_REQUEST['first_name'])){
$first_name = stripslashes($_REQUEST['first_name']); // removes backslashes
$first_name = mysqli_real_escape_string($con,$first_name); //escapes special characters in a string
$last_name = stripslashes($_REQUEST['last_name']);
$email = stripslashes($_REQUEST['email']);
$email = mysqli_real_escape_string($con,$email);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$phone = stripslashes($_REQUEST['phone']);
$phone = mysqli_real_escape_string($con,$phone);
$query = "INSERT into `tbl_users` (first_name, last_name, email, password, phone) VALUES ('$first_name','$last_name', '$email', '".md5($password)."', '$phone')";
$result = mysqli_query($con,$query);
if($result){
echo "<div class='form'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
}else{
?>
<form name="create" action="" method="post">
<label for="chkYes1">
<input type="radio" id="chkYes1" name="chk" onclick="ShowHideDiv()" />
Private User
</label>
<br>
<label for="chkYes2">
<input type="radio" id="chkYes2" name="chk" onclick="ShowHideDiv() " checked="checked" />
Professional Agent
</label>
<br>
<br>
<div id="dvtext1" style="display: none" class="lgntxt">
First Name *
<br>
<input type="text" id="txtBox" name="first_name" required />
</div>
<br>
<div id="dvtext9" style="display: none" class="lgntxt">
Last Name *
<br>
<input type="text" id="txtBox" name="last_name" required />
</div>
<br>
<div id="dvtext10" style="display: none" class="lgntxt">
Email Address *
<br>
<input type="text" id="txtBox" name="email" required />
</div>
<br>
<div id="dvtext11" style="display: none" class="lgntxt">
Password *
<br>
<input type="password" id="txtBox" name="password" required />
</div>
<br>
<div id="dvtext12" style="display: none" class="lgntxt">
Repeat password *
<br>
<input type="password" id="txtBox" />
</div>
<br>
<div id="dvtext13" style="display: none" class="lgntxt">
Phone Number *
<br>
<input type="text" id="txtBox" name="phone" required />
</div>
<br>
<div id="dvtext2" class="lgntxt" style="display: none">
Agency Name *
<br>
<input type="text" id="txtBox" name="aname" />
</div>
<br>
<div id="dvtext3" class="lgntxt" style="display: none">
Office Address *
<br>
<input type="text" id="txtBox" name="oadd" />
</div>
<br>
<div id="dvtext4" class="lgntxt" style="display: none">
City *
<br>
<input type="text" id="txtBox" name="city" />
</div>
<br>
<div id="dvtext5" class="lgntxt" style="display: none">
Zip Code *
<br>
<input type="text" id="txtBox" name="zip" />
</div>
<br>
<div id="dvtext7" class="lgntxt" style="display: none">
Office Phone Number *
<br>
<input type="text" id="txtBox" name="ophn" />
</div>
<br>
<div id="dvtext8" class="lgntxt" style="display: none">
Office Email Address *
<br>
<input type="text" id="txtBox" name="oemail" />
</div>
<!-- <button style="display: none" id="btn1" class="btn third" type="submit" name="submit" value="Submit">CONTINUE</button> -->
<input type="submit" name="submit" value="Register" style="display: none" id="btn1" class="btn third" />
</form>
</div>
</div>
</div>
</div>
<?php } ?>