这是错误
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'WHERE Jobs.CatagoryId= 1' at line 2
.....
Jobs
----
JobID
CategoryID
JobName
JobDescription
JobNumber
Categories
---------
CategoryID // 11 categories..
CategoryDescription
根据droplist中的用户选择,它将选择应存储数据的类别。 并插入所有数据用户输入框字段
<?php
session_start();
if( isset($_SESSION['username']) ){
if(isset($_POST['add'])){
if(isset($_POST['add']))
{
$errorMessage = "";
if(($_POST['lists'])== 0) // trying to get error if user don't choose.
{
$errorMessage .= "<li>You Forgot to Choose !</li>";
}
if(empty($_POST['JobName']))
{
$errorMessage .= "<li>You Forgot To Enter A Job Name !</li>";
}
if(empty($_POST['Description']))
{
$errorMessage .= "<li>You Forgot To Enter A Description !</li>";
}
if(empty($_POST['NoStudent']))
{
$errorMessage .= "<li>You Forgot To Enter A Student Number !</li>";
}
if(empty($_POST['dueDate']))
{
$errorMessage .= "<li>You Forgot To Enter A Due Date !</li>";
}
$lists = $_POST['lists'];
$JN = $_POST['JobName'];
$DES = $_POST['Description'];
$NoS = $_POST['NoStudent'];
$DuDate = $_POST['dueDate'];
if(!empty($errorMessage))
{
echo("<p>There was an error with your form:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
die();
}
}
$table="";
switch($lists)
{
case '1':
$table ="1";
break;
case '2':
$table ="2";
break;
//.........other cases..........//
case '3':
$table ="3";
break;
case '4':
$table ="4";
break;
case '5':
$table ="5";
break;
case '6':
$table ="6";
break;
case '7':
$table ="7";
break;
case '7':
$table ="8";
break;
case '8':
$table ="9";
break;
case '9':
$table ="10";
break;
case '10':
$table ="11";
break;
case '11':
$table ="12";
break;
default;
echo 'Unsupported category';
break;
}
if ($table != ""){
//Connect to DB
include('../CIEcon.php'); //$dbCIE
$sql = "INSERT INTO Jobs(JobName,Description,NoStudent,DueDate)
VALUES ('$JN','$DES','$NoS','$DuDate') WHERE Jobs.CatagoryId= ". $table . " ";
mysqli_query($dbCIE, $sql) or die(mysqli_error($dbCIE));
}
echo "You Successfuly Added a new Job ...";
mysqli_close($dbCIE);
}
else { echo '
<form action= "AddJob.php" method = "post">
<table width ="100%" cellpadding ="4" border="1" >
<tr style ="color: white; background-color: #f26822 ; ">
<th>Select a Catagory</th>
<th>Jobs Name</th>
<th>Description</th>
<th> No Students needed</th>
<th>Due Date</th>
</tr>';
echo "<tr>
<td>".
"<select name = lists >
<option name= nothing value= 0 selected >Choose a Catagory</option>
<option name= nothing value= 1> Advertising </option>
<option name= nothing value= 2> Fiscal </option>
<option name= nothing value= 3> Food </option>
<option name= nothing value= 4> Shopping </option>
<option name= nothing value= 5> Rentals </option>
<option name= nothing value= 6> Setting up </option>
<option name= nothing value= 7> Performances </option>
<option name= nothing value= 8> Registration/Ushering </option>
<option name= nothing value= 9> Master of Ceremonies </option>
<option name= nothing value= 10> Cleaning up </option>
<option name= nothing value= 11> Others </option>
</select>"
." </td>
<td> "."<input type=text name=JobName maxlength=50 placeholder='Enter Job Name '>" ." </td>
<td> "."<input type=text name=Description maxlength=50 placeholder='Enter Description '>" ." </td>
<td> ". "<input type=text name=NoStudent maxlength=50 onkeypress=return isNumber(event) placeholder='ONLY NUMBERS'/>" . "</td>
<td>". "<input type=text name=dueDate maxlength=50 placeholder='YYYY-MM-DD'>" ." </td>
</tr>";
echo '
</table>
<br/>
<div align="center">
<input type="submit" name="add" value="Add" />
<input type="reset" value="Clear" />
</div>
</form>
';
}
}else{echo "must logout to see this page..!!";}
?>
<html>
<style type="text/css">
body{
margin-top: 80px;
background-color: #23438e ;
}
table{
background-color: white;
}
</style>
<head><title> Add.. </title></head>
<br>
<body>
<a href= "../AdminIndex.php" > <button style="margin-left:auto;margin-right:auto;display:block;margin-top:0%;margin-bottom:0%"> Main Page </button></a>
</body>
</html>
答案 0 :(得分:1)
如果$表存在于“Categories.CategotyID”中,而“Jobs.JobID”是自动递增的,则查询可以是:
$sql = "INSERT INTO Jobs(`JobID`, `CategoryID`, `JobName`,`Description`,`NoStudent`)
VALUES (NULL,{$table},'$JN','$DES','$NoS');
或
$sql = "INSERT INTO Jobs VALUES (NULL,{$table},'$JN','$DES','$NoS');
您的查询包含属性DuDate,存在于Jobs ??
中