我有一个列错误,但我似乎无法找到问题。我试图将患者的detials添加到名为“Patient”的表格中。我收到以下错误:
无法输入数据:列数与第1行的值计数不匹配
任何人都可以帮忙解决原因吗?
PHP代码:
<?php
if(isset($_POST['add'])) {
$dbhost = 'localhost';
$dbuser = 'carl';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$PatientName = $_POST['PatientName'];
$IDNumber = $_POST['IDNumber'];
$Gender = $_POST['Gender'];
$Address = $_POST['Address'];
$LandlineTel = $_POST['LandlineTel'];
$MobileTel = $_POST['MobileTel'];
$DOB = $_POST['DOB'];
$Conditions = $_POST['Conditions'];
$NextOfKin = $_POST['NextOfKin'];
$ClinicNo = $_POST['ClinicNo'];
$Appointments = $_POST['Appointments'];
$sql = "INSERT INTO Patient ". "(PatientName,IDNumber, Gender, Address, LandlineTel, MobileTel, DOB, Conditions, NextOfKin, ClientNo, Appointments) ". "VALUES('$PatientName','$IDNumber', $Gender, $Address, $LandlineTel, $MobileTel, $DOB, $Conditions, $NextOfKin, $ClinicNo, $Appointments, NOW())";
mysql_select_db('MedicalDB');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}else {
?>
HTML表单代码:
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border = "0" cellspacing = "1"
cellpadding = "2">
<tr>
<td width = "100">Employee Name</td>
<td><input name = "PatientName" type = "text"
id = "PatientName"></td>
</tr>
<tr>
<td width = "100">ID Number</td>
<td><input name = "IDNumber" type = "text"
id = "IDNumber"></td>
</tr>
<tr>
<td width = "100">Gender</td>
<td><input name = "Gender" type = "text"
id = "Gender"></td>
</tr>
<tr>
<td width = "100">Address</td>
<td><input name = "Address" type = "text"
id = "Address"></td>
</tr>
<tr>
<td width = "100">LandlineTel</td>
<td><input name = "LandlineTel" type = "text"
id = "LandlineTel"></td>
</tr>
<tr>
<td width = "100">MobileTel</td>
<td><input name = "MobileTel" type = "text"
id = "MobileTel"></td>
</tr>
<tr>
<td width = "100">DOB</td>
<td><input name = "DOB" type = "text"
id = "DOB"></td>
</tr>
<tr>
<td width = "100">Conditions</td>
<td><input name = "Conditions" type = "text"
id = "Conditions"></td>
</tr>
<tr>
<td width = "100">Next Of Kin</td>
<td><input name = "NextOfKin" type = "text"
id = "NextOfKin"></td>
</tr>
<tr>
<td width = "100">Clinic Number</td>
<td><input name = "ClinicNo" type = "text"
id = "ClinicNo"></td>
</tr>
<tr>
<td width = "100">Appointments</td>
<td><input name = "Appointments" type = "text"
id = "Appointments"></td>
</tr>
<tr>
<td width = "100"> </td>
<td> </td>
</tr>
<tr>
<td width = "100"> </td>
<td>
<input name = "add" type = "submit" id = "add"
value = "Add Employee">
</td>
</tr>
</table>
</form>
答案 0 :(得分:0)
您的查询未指定您尝试将NOW()
的值插入的列。你有11列和12个值。