-2
對不起,如果我問得太多,這只是我耗盡時間,我真的需要你的幫助,我試圖根據用戶輸入INSERT數據到我的表中.. 這是我的表..和相關如何將數據添加到您的連接表
這是錯誤
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>
那麼,它有什麼問題? –
它告訴我在MYSQL查詢中有一個錯誤 – aymanko
沒有'''INSERT INTO ... WHERE ...''' - 請參閱語法參考,例如, http://dev.mysql.com/doc/refman/5.7/en/insert.html –