为什么表单不起作用?在提交输入后,它不会添加到数据库中。查询错误还是表单错误?
这是将数据编码为表单的页面代码。
<html>
<?php
include ("css.php");
?>
<head>
</head>
<ul>
<li><a href="employeemenu.php">Home</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</br>
<h1 align = center>GPC INSPECTION FORM</h1>
</html>
<?php
session_start();
include ("css.php");
require_once('/mysql_connect.php');
if (!isset($_SESSION['id'])){
$_SESSION['id']=$_GET['id'];
}
if (isset($_POST['submit'])){
$message = null;
if($_POST['spraying']=="1"){
$sprayingInside="1";
$sprayingOutside="0";
}
else{
$sprayingInside="0";
$sprayingOutside="1";
}
$spremarks = $_POST['spremarks'];
if($_POST['misting']=="1"){
$mistingInside="1";
$mistingOutside="0";
}
else{
$mistingInside="0";
$mistingOutside="1";
}
$mremarks = $_POST['mremarks'];
if($_POST['fogging']=="1"){
$foggingInside="1";
$foggingOutside="0";
}
else{
$foggingInside="0";
$foggingOutside="1";
}
$fremarks = $_POST['fremarks'];
$ratbaiting = $_POST['ratbaiting'];
$gluetrapping = $_POST['gluetrapping'];
$mechtrapping = $_POST['mechtrapping'];
$rodremarks = $_POST['rodremarks'];
$gelbaiting = $_POST['gelbaiting'];
$gelremarks = $_POST['gelremarks'];
$larvicting = $_POST['larvicting'];
$lremarks = $_POST['lremarks'];
$birdcontrol = $_POST['birdcontrol'];
$bremarks = $_POST['bremarks'];
$catcontrol = $_POST['catcontrol'];
$cremarks = $_POST['cremarks'];
$conductedBy = $_SESSION['userID'];
$others = $_POST['otherTreatments'];
$areas = $_POST['areasofin'];
$date = $_POST['date'];
$treatFreq = $_POST['treatFreq'];
$rovFreq= $_POST['rovFreq'];
$necRep= $_POST['necRep'];
$areasofin= $_POST['areasofin'];
$allremarks= $_POST['allremarks'];
$reportID = $_SESSION['id'];
这是查询。我需要上面的所有变量来进行查询。
$query="INSERT INTO gpc_report (treatmentFrequency, rovingFrequency, necessaryReports, areasIncluded, sprayingInside, sprayingOutside, sprayingRemarks, mistingInside, mistingOutside, mistingRemarks, foggingInside, foggingOutside, foggingRemarks, ratBaiting, glueTrapping, mechanicalTrapping, rodentControlRemarks, gelBaiting, gelBaitingRemarks, larvicting, larvictingRemarks, birdControl, birdControlRemarks, catControl, catControlRemarks, otherSpecificTreatments, areasOfInfestationObserved, remarks, conductedBy, dateOfInspection)
values ({$treatFreq}','{$rovFreq}', '{$necRep}', '{$areas}', '{$sprayingInside}', '{$sprayingOutside}', '{$spremarks}', '{$mistingInside}', '{$mistingOutside}', '{$mremarks}', '{$foggingInside}', '{$foggingOutside}', '{$fremarks}', '{$ratbaiting}', '{$gluetrapping}', '{$mechtrapping}', '{$rodremarks}', '{$gelbaiting}', '{$gelremarks}', '{$larvicting}', '{$lremarks}', '{$birdcontrol}', '{$bremarks}', '{$catcontrol}', '{$cremarks}', '{$others}', '{$areasofin}', '{$allremarks}', '{$conductedBy}', '{$date}')";
$result=mysqli_query($dbc,$query);
if (isset($message)){
echo '<font color="red">'.$message. '</font>';
}
}
$query2="select users.firstname, users.lastname, users.address, users.username, users.contactNo, users.email
from users join gpc_orders on users.userID = gpc_orders.customerID
where gpc_orders.active=1";
$result2=mysqli_query($dbc,$query2);
$row2=mysqli_fetch_array($result2,MYSQLI_ASSOC);
这是表单的开头。上面的查询仅用于显示客户信息。
echo '<div align = "center"> <form action= '.$_SERVER['PHP_SELF'].' method="post" align="center">
<b>Client Information</b><br>
<br> Name: '.$row2['firstname'].' '.$row2['lastname'].'
<br> Username: '.$row2['username'].'
<br> Address: '.$row2['address'].'
<br> Contact Number: '.$row2['contactNo'].'
<br> E-mail: ' .$row2['email'].'<br>';
echo '
</br>
</br>Treatment Frequency: <input type="text" id="treatFreq" name="treatFreq">
</br>Roving Frequency: <input type="text" id="rovFreq" name="rovFreq">
<br>Necessary Reports: <input type="text" id="necRep" name="necRep">
</br>Areas Included: <input type="text" id="areas" name="areas">
</br>
</br>
</br>PEST CONTROL TREATMENT
</br>
</br>Spraying:
<select id="spraying" name="spraying">
<option value="1">Inside</option>
<option value="0">Outside</option>
</select>
<br>
</br>Remarks: <input type="text" id="spremarks" name="spremarks"><br>
</br>
</br>Misting: <select id="misting" name="misting">
<option value="1">Inside</option>
<option value="0">Outside</option>
</select>
<br>
</br>Remarks: <input type="text" id="mremarks" name="mremarks"><br>
</br>
</br>Fogging: <select id="fogging" name="fogging">
<option value="1">Inside</option>
<option value="0">Outside</option>
</select>
<br>
</br>Fogging Remarks: <input type="text" id="fremarks" name="fremarks"><br>
</br>
</br>Rat Baiting: <select id="ratbaiting" name="ratbaiting">
<option value="1">Needed</option>
<option value="0">Not Needed</option>
</select>
<br>
</br>Glue Trapping: <select id="gluetrapping" name="gluetrapping">
<option value="1">Needed</option>
<option value="0">Not Needed</option>
</select>
<br><br>
</br>Mechanical Trapping: <select id="mechtrapping" name="mechtrapping">
<option value="1">Needed</option>
<option value="0">Not Needed</option>
</select>
<br><br>
</br>Rodent Control Remarks: <input type="text" id="rodremarks" name="rodremarks"><br>
</br>
</br>Gelbaiting: <select id="gelbaiting" name="gelbaiting">
<option value="1">Needed</option>
<option value="0">Not Needed</option>
</select>
<br><br>
</br>Remarks: <input type="text" id="gelremarks" name="gelremarks"><br>
</br>
</br>Larvicting: <select id="larvicting" name="larvicting">
<option value="1">Needed</option>
<option value="0">Not Needed</option>
</select>
<br><br>
</br>Remarks: <input type="text" id="lremarks" name="lremarks"><br>
</br>
</br>Bird Control: <select id="birdcontrol" name="birdcontrol">
<option value="1">Needed</option>
<option value="0">Not Needed</option>
</select>
<br><br>
</br>Remarks: <input type="text" id="bremarks" name="bremarks"><br>
</br>
</br>Cat Control: <select id="catcontrol" name="catcontrol">
<option value="1">Needed</option>
<option value="0">Not Needed</option>
</select>
<br><br>
</br>Remarks: <input type="text" id="cremarks" name="cremarks"><br>
</br>
</br>Others: <input type="text" id="otherTreatments" name="otherTreatments"><br>
</br>
</br>Areas of Infestation Observed: <input type="text" id="areasofin" name="areasofin"><br>
</br>
</br>Remarks:<input type="text" id="allremarks" name="allremarks"><br>
</br>Date of Inspection:<input type="text" id="date" name="date"><br>
';
?>
<button type="submit" id="submit" name="submit">Submit</button>
</form>
</div>
<br>
<br>
<a href="selectuser.php">Back</a>
</br>