我是PHP新手在“填充并提交”之后,它不会显示任何消息,也不会向数据库中添加数据。自动重定向到localhost文件夹。而且,如果不向其中填充数据,我也不能留下一些不需要的单选按钮。如您在代码中所看到的,仅当用户拥有数据时,才必须添加某些数据,否则,他可以选择其他选项并填写表格。但是,即使我选择“我没有数据选项”,它也会要求填写该字段。请帮忙。这是HTML和PHP代码。任何帮助将不胜感激。
<?php
include('Uni_assets/db.php')
?>
<!DOCTYPE html>
<html>
<head>
<title>Consumer Complaint</title>
<link href="Uni_assets/css.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
</head>
<body>
<div class="header">
<img src="Uni_assets/header.png" align="center">
</div>
<div class="center">
<div class="testbox">
<form action="/">
<h1>Consumer Complaint Form</h1>
<h2>Information About You</h2>
<h4>All your data is confidential and will never be released</h4>
<div >
<p><B>Your Full Name</B></p>
<div class="name-item">
<div>
<select name="title" required>
<option value="" disabled selected hidden><B>Title</option>
<option value="Dr.">Dr.</option>
<option value="Miss.">Miss.</option>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Prof.">Prof.</option>
<option value="Rev .">Rev .</option>
<option value="Rev . Fr">Rev . Fr .</option>
</select>
</div>
<input type="text" name="name" placeholder="Full Name" required />
</div>
</div>
<div class="item">
<p><B>Your NIC</B></p>
<div class="name-item2">
<input type="text" name="NIC" maxlength="12" required/>
</div>
</div>
<div class="item">
<p><B>Your Address</B></p>
<div class="name-item2">
<input type="text" name="addr1" placeholder="" required/>
<!-- <input type="text" name="addr2" placeholder="Address line 2 (Optional)"/> -->
</div>
</div>
<div class="item">
<p><B>Your Email</B></p>
<div class="name-item2">
<input type="text" name="emaill" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" required/>
</div>
</div>
<div class="item">
<p><B>Your Telephone Number</B></p>
<div class="name-item2">
<input type="text" name="phone" value="+94" maxlength="12" required/>
</div>
</div>
<div class="item preferred-metod">
<p><B>Preferred method of contact (You may select more than one)</B></p>
<div class="preferred-metod-item">
<label><input type="checkbox" name="chk1"> <span>Email</span></label>
<label><input type="checkbox" name="chk2"> <span>Phone</span></label>
<label><input type="checkbox" name="chk3"> <span>Mail</span></label>
</div>
</div>
<h2><B>Information about your complaint</B></h2>
<div class="item">
<p><B>Name of the business</B></p>
<div class="name-item2">
<input type="text" name="bname" required/>
</div>
</div>
<div class="item">
<p><B>Product/Service</B></p>
<div class="name-item2">
<input type="text" name="productname" required/>
</div>
</div>
<div >
<p><B>Telephone Number of the business</B></p>
<div>
<div>
<input type="radio" name="choice-phone" id="choice-phone-Yes" required>
<label for="choice-phone-Yes">I <b>Know</b> the telephone number of this business</label>
<div class="reveal-if-active">
<label for="which-Yes">Please enter the telephone number of this business</label>
<input type="text" id="which-Yes" value="+94" maxlength="12" name="bphone" class="require-if-active" data-require-pair="#choice-phone-Yes">
</div>
</div>
<div>
<input type="radio" name="choice-phone" id="choice-phone-No">
<label for="choice-phone-No">I <b>Don't know</b> the telephone number of this business</label>
</div>
</div>
<?php
$countries = array("Kandy", "Colombo", "Gampaha", "Ampara", "Badulla", "Anuradhapura", "Jaffna", "Kaluthara", "Kegalle", "Kilinochchi", "Kurunegala", "Mannar", "Matale", "Monaragala", "Matara", "Nuwara Eliya", "Polonnnaruwa", "Puthathalama", "Trincomalee", "Ratnapura", "Vavuniya", "Mullaitivu", "Hambantota", "Batticaloa", "Ampara");
?>
<div class="form-group">
<p><B>Business Located District</B></p>
<select name="country" required>
<option value="" disabled selected hidden><B>Select the district</option>
<?php
foreach($countries as $key => $value):
echo '<option value="'.$value.'">'.$value.'</option>'; //close your tags!!
endforeach;
?>
</select>
</div>
<div >
<p><B>Email of the business</B></p>
<div>
<div>
<input type="radio" name="choice-email" id="choice-email-Yes" required>
<label for="choice-email-Yes">I <b>Know</b> the email of this business</label>
<div class="reveal-if-active">
<label for="which-Yes">Please enter the email of this business</label>
<input type="text" id="which-Yes" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" maxlength="100" name="bemail" class="require-if-active" data-require-pair="#choice-email-Yes" >
</div>
</div>
<div>
<input type="radio" name="choice-email" id="choice-email-No">
<label for="choice-email-No">I <b>Don't know</b> the email of this business</label>
</div>
</div>
<div >
<p><B>Address of the business</B></p>
<div>
<div>
<input type="radio" name="choice-add" id="choice-add-Yes" required>
<label for="choice-add-Yes">I <b>Know</b> the address of this business</label>
<div class="reveal-if-active">
<label for="which-Yes">Please enter the address of this business</label>
<div class="name-item2">
<input type="text" name="baddr1" placeholder="" required/>
<!-- <input type="text" name="baddr2" placeholder="Address line 2 (Optional)"/> -->
</div>
</div>
</div>
<div>
<input type="radio" name="choice-add" id="choice-add-No">
<label for="choice-add-No">I <b>Don't know</b> the address of this business</label>
</div>
</div>
<div >
<p><B>Incident Timestamp</B></p>
<div>
<div>
<input type="radio" name="choice-happ" id="choice-happ-Yes" required>
<label for="choice-happ-Yes">This happened only once</label>
<div class="reveal-if-active">
<label for="which-Yes">Please enter the date and time issue occurred</label>
<div class="name-item2">
<input type="date" name="idate" required/>
<input type="time" name="itime" required/>
</div>
</div>
</div>
<div>
<input type="radio" name="choice-happ" id="choice-happ-No">
<label for="choice-happ-No">This happenes frequently</label>
</div>
<div>
<input type="radio" name="choice-happ" id="choice-happ-No2">
<label for="choice-happ-No2">This happenes occasionally</label>
</div>
</div>
<div class="item">
<p><B>Complaint</B></p>
<p>Please describe your complaint in detail. Include the names of persons, locations, and dates involved. If this complaint is against specific person(s), please list their names and titles</p>
<textarea rows="10" name="compl"></textarea>
</div>
<div >
<p><B>Do you have any evidence (Images/Videos/Audio Records)?</B></p>
<div>
<div>
<input type="radio" name="choice-eved" id="choice-eved-Yes" required>
<label for="choice-eved-Yes"><b>Yes</b>, I have evidence?</label>
<div class="reveal-if-active">
<div class="item">
<p>You can attach multiple files. Maximum upload size is 10mb</p>
<input type="file" name="fileToUpload" id="fileToUpload" class="custom-file-input" multiple>
</div>
</div>
</div>
<div>
<input type="radio" name="choice-eved" id="choice-eved-No">
<label for="choice-eved-No"><b>No</b>, I don't have any evidence</label>
</div>
</div>
</div>
<div >
<p><B>Have you informed a responsible officer about this before?</B></p>
<div>
<div>
<input type="radio" name="choice-att" id="choice-att-Yes" required>
<label for="choice-att-Yes"><b>Yes</b>, I have informed a responsible officer about this before?</label>
<div class="reveal-if-active">
<div class="name-item2">
<div class="item">
<p>What attempts have you made to resolve this complaint up to now? Please state who you contacted and what transpired</p>
<textarea rows="5" name="attmp1"></textarea>
</div>
<div class="item">
<p>Why do you think the complaint was not able to be resolved in your prior attempts?</p>
<textarea rows="5" name="attmp2"></textarea>
</div>
</div>
</div>
</div>
<div>
<input type="radio" name="choice-att" id="choice-att-No">
<label for="choice-att-No"><b>No</b>, I'm informing the CAA directly</label>
</div>
</div>
</div>
<div class="item">
<p>What resolution would you consider fair? What resolution do you seek?</p>
<textarea rows="5" name="ress"></textarea>
</div>
<div class="item">
<p>Any other information you want to provide?</p>
<textarea rows="5" name="otheri"></textarea>
</div>
<?php $Random_code=rand(0000000000,9999999999);
$evid="evident";
?>
<div >
<input type="submit" name="submit" class="btn-block">
<?php
if(isset($_POST['submit']))
{
$code1=$Random_code;
if($code1!="$code")
{
$msg="Invalide code";
}
else
{
$check="SELECT * FROM consumer_complaints WHERE Inquiry_ID = '$Random_code'";
$rs = mysqli_query($con,$check);
$data = mysqli_fetch_array($rs, MYSQLI_NUM);
if($data[0] > 10) {
echo "<script type='text/javascript'> alert('Something went wrong. We Fixed it. Try again now'); window.location.href='CAAC/form.php';</script>";
}
else
{
$newUser="INSERT INTO `consumer_complaints`(
`Inquiry_ID`,
`Title`,
`F_Name`,
`Y_NIC`,
`Y_Address`,
`Y_email`,
`Y_phone`,
`P_M_contact_Mail` ,
`P_M_contact_Email` ,
`P_M_contact_Phone` ,
`B_Name` ,
`Product_Service`,
`B_Phone`,
`B_Dic`,
`B_Email`,
`B_Address`,
`I_Date`,
`I_Time`,
`Complaint`,
`Evidence`,
`Attempt`,
`Attempt_fail`,
`Resolution`,
`Other_Info`
)
VALUES (
'$Random_code',
'$_POST[title]',
'$_POST[F_name]',
'$_POST[NIC]',
'$_POST[addr1]',
'$_POST[emaill]',
'$_POST[phone]',
'$_POST[chk3]',
'$_POST[chk1]',
'$_POST[chk2]',
'$_POST[bname]',
'$_POST[productname]',
'$_POST[bphone]',
'$_POST[country]',
'$_POST[bemail]',
'$_POST[baddr1]',
'$_POST[idate]',
'$_POST[itime]',
'$_POST[compl]',
'$evid',
'$_POST[attmp1]',
'$_POST[attmp2]',
'$_POST[ress]',
'$_POST[otheri]',
)";
if (mysqli_query($con,$newUser))
{
echo "<script type='text/javascript'> alert('Your complaint has been sent'); window.location.href='CAAC/form.php'</script>";
}
else
{
echo "<script type='text/javascript'> alert('Something went wrong. We Fixed it. Try again now'); window.location.href='CAAC/form.php'</script>";
}
}
$msg="Something went wrong. We Fixed it. Try again now";
}}
?>
</form>
</div>
</div>
</body>
</html>
这是需要的情况下的css代码
html, body {
margin: 0;
min-height: 100%;
}
div, form, input, select, p {
padding: 0;
margin: 0;
outline: none;
font-family: Roboto, Arial, sans-serif;
font-size: 14px;
color: #666;
line-height: 22px;
}
h1 {
margin: 15px 0;
font-weight: 400;
}
h2 {
margin: 15px 0;
font-weight: 400;
padding: 2px;
}
h4 {
margin: 15px 0;
font-weight: 400;
padding: 5px;
background-color: #b3deff;
}
.center {
margin: auto;
width: 60%;
padding: 10px;
}
.header {
background-color: linear-gradient(red, yellow);
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.testbox {
display: flex;
height: inherit;
padding: 3px;
}
form {
width: 100%;
padding: 20px;
background: #fff;
box-shadow: 0 2px 5px #ccc;
}
input, select, textarea {
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
input {
padding: 5px;
}
select {
width: 100%;
padding: 7px 0;
background: transparent;
}
textarea {
width: calc(100% - 6px);
}
.item {
position: relative;
margin: 10px 0;
width: 100%;
}
.item:hover p, .item:hover i {
color: #095484;
}
input:hover, select:hover, textarea:hover, .preferred-metod label:hover input {
box-shadow: 0 0 5px 0 #095484;
}
.preferred-metod label {
display: block;
margin: 5px 0;
}
.preferred-metod:hover input {
box-shadow: none;
}
.preferred-metod-item input, .preferred-metod-item span {
width: auto;
vertical-align: middle;
}
.preferred-metod-item input {
margin: 0 5px 0 0;
}
input[type="date"]::-webkit-inner-spin-button {
display: none;
}
.item i, input[type="date"]::-webkit-calendar-picker-indicator {
position: absolute;
font-size: 20px;
color: #a9a9a9;
}
.item i {
right: 1%;
top: 30px;
z-index: 1;
}
[type="date"]::-webkit-calendar-picker-indicator {
right: 0;
z-index: 2;
opacity: 0;
cursor: pointer;
}
.btn-block {
margin-top: 20px;
text-align: center;
}
button {
width: 150px;
padding: 10px;
border: none;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
background-color: #095484;
font-size: 16px;
color: #fff;
cursor: pointer;
}
button:hover {
background-color: #0666a3;
}
@media (min-width: 568px) {
.name-item, .city-item {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.name-item2 {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.name-item2 input {
width: calc(100%);
}
.name-item3 {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.name-item3 input {
width: calc(20%);
}
.city-item input {
width: calc(50% - 20px);
}
.name-item input {
width: calc(90%);
}
.city-item select {
width: calc(50% - 8px);
}
}
.reveal-if-active {
opacity: 0;
max-height: 0;
overflow: hidden;
font-size: 16px;
-webkit-transform: scale(0.8);
transform: scale(0.8);
-webkit-transition: 0.5s;
transition: 0.5s;
}
.reveal-if-active label {
display: block;
margin: 0 0 3px 0;
}
.reveal-if-active input[type=text] {
width: 100%;
}
input[type="radio"]:checked ~ .reveal-if-active, input[type="checkbox"]:checked ~ .reveal-if-active {
opacity: 1;
max-height: 500px;
padding: 10px 20px;
-webkit-transform: scale(1);
transform: scale(1);
overflow: visible;
}
.custom-file-input {
color: transparent;
}
.custom-file-input::-webkit-file-upload-button {
visibility: hidden;
}
.custom-file-input::before {
content: 'Attach evidence files';
color: black;
display: inline-block;
background: -webkit-linear-gradient(top, #f9f9f9, #e3e3e3);
border: 1px solid #999;
border-radius: 3px;
padding: 5px 8px;
outline: none;
white-space: nowrap;
-webkit-user-select: none;
cursor: pointer;
text-shadow: 1px 1px #fff;
font-weight: 700;
font-size: 10pt;
}
.custom-file-input:hover::before {
border-color: black;
}
.custom-file-input:active {
outline: 0;
}
.custom-file-input:active::before {
background: -webkit-linear-gradient(top, #e3e3e3, #f9f9f9);
}
您必须将所有输入和按钮插入表单中
将所有代码以及输入和按钮插入此表单内
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"] ?>" >
</form>
应该去,让我知道!尝试像这样更新php:
if($data[0] > 10) {
echo "<script type='text/javascript'> alert('Something went wrong. We Fixed it. Try again now'); window.location.href='CAAC/form.php';</script>";
}
else
{
$newUser="INSERT INTO `consumer_complaints`(
`Inquiry_ID`,
`Title`,
`F_Name`,
`Y_NIC`,
`Y_Address`,
`Y_email`,
`Y_phone`,
`P_M_contact_Mail` ,
`P_M_contact_Email` ,
`P_M_contact_Phone` ,
`B_Name` ,
`Product_Service`,
`B_Phone`,
`B_Dic`,
`B_Email`,
`B_Address`,
`I_Date`,
`I_Time`,
`Complaint`,
`Evidence`,
`Attempt`,
`Attempt_fail`,
`Resolution`,
`Other_Info`
)
VALUES (
'$Random_code',
'$_POST[title]',
'$_POST[F_name]',
'$_POST[NIC]',
'$_POST[addr1]',
'$_POST[emaill]',
'$_POST[phone]',
'$_POST[chk3]',
'$_POST[chk1]',
'$_POST[chk2]',
'$_POST[bname]',
'$_POST[productname]',
'$_POST[bphone]',
'$_POST[country]',
'$_POST[bemail]',
'$_POST[baddr1]',
'$_POST[idate]',
'$_POST[itime]',
'$_POST[compl]',
'$evid',
'$_POST[attmp1]',
'$_POST[attmp2]',
'$_POST[ress]',
'$_POST[otheri]',
)";
$send = mysqli_query($con,$newUser);
if (!$send)
{
echo "<script type='text/javascript'> alert('Something went wrong. We Fixed it. Try again now'); window.location.href='CAAC/form.php'</script>";
}
else
{
echo "<script type='text/javascript'> alert('Your complaint has been sent'); window.location.href='CAAC/form.php'</script>";
}
}