我在哪裏做錯了。我得到這個錯誤:SQLSTATE [23000]:完整性約束違規:1048'duedate'列不能爲空
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'duedate' cannot be null
我的代碼如下,我試圖插入數據到一個MySQL表使用PDO。但它一直在發送一些錯誤,即不能爲空。即使我在表格中輸入duedate。
<?php
if(empty($_SESSION['studentSession'])){
redirectTo("index.php?tag=login&message=createA");
}else{
?>
<!-- <head> -->
<script type = "text/javascript">
var pCount = 2;
function appendChildtoParent(){
var idValname = "fileToUpload"+pCount;
//alert(idValname);
var newElem = document.createElement ("div");
newElem.innerHTML = 'Select file to upload:<div class = "form-group"> <input type="file" name='+idValname+' id='+pCount+'></div><div class = "form-group"></div>';
var parentDiv = document.getElementById("parentImageDiv");
parentDiv.appendChild(newElem);
var fileUploadAct = document.getElementById("uploadButton1");
fileUploadAct.value = "Upload file(s)";
if(fileUploadAct.disabled = "true"){
fileUploadAct.disabled = false;
}
pCount = pCount + 1;
}
function postHomework(){
var description = tinyMCE.activeEditor.getContent({format : 'html'});
description = encodeURIComponent(description);
var categories = document.getElementById("categories").value;
categories = encodeURIComponent(categories);
var question = document.getElementById("questionItself").value;
question = encodeURIComponent(question);
var memberID = document.getElementById("memberID").value;
memberID = encodeURIComponent(memberID);
var amount = document.getElementById("amountText").value;
amount = encodeURIComponent(amount);
//alert(description);
if(question == ""){
alert("Enter your question");
}
else if(description == ""){
alert("Enter a description");
}
else if(categories == ""){
alert("Choose category");
}
else if(amount == ""){
alert("Enter amount you are willing to pay");
}
else{
var tutorial = document.getElementById("checkboxIns");
if(tutorial.checked){
var tutorialType = "tutorial";
}else{
var tutorialType = "question";
}
var emailVal = document.getElementById("emailcheck");
if(emailVal.checked){
var notificatinSend = "1";
} else{
var notificatinSend = "2";
}
//alert(notificatinSend);
var hr;
if (window.XMLHttpRequest){
hr = new XMLHttpRequest();
}else{
hr = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "posthomeworkAJAX.php";
var vars = "description="+description+"& categories="+categories+"&question="+question+"&memberID="+memberID+"&amount="+amount+"&tutorialType="+tutorialType+"¬ificatinSend="+notificatinSend;
//var vars = "description="+description;
hr.open("POST",url,true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function(){
if(hr.readyState == 4 && hr.status == 200){
var return_data = hr.responseText;
//document.getElementById("filesUploadBTN").click();
//alert("Saved succeessfully");
//window.location = "my-homework";
document.getElementById("msg").innerHTML = return_data;
}
}
hr.send(vars);
document.getElementById("status").innerHTML = "Processing...";
}
}
function checkboxIns(){
var chckIns = document.getElementById("checkboxIns");
if(chckIns.checked){
//alert("Checked");
document.getElementById("tutorialCheck").innerHTML = "Check this box only if you are a teacher";
document.getElementById("questionNotification").innerHTML = "";
}
else{
document.getElementById("tutorialCheck").innerHTML = "";
document.getElementById("questionNotification").innerHTML = "Do not post private information in a question (e.g. real name, credentials) . Send it directly to the teacher doing your homework later on";
//alert("Unchecked");
}
}
function tempSave(attID){
var attVal = document.getElementById(attID).value;
if(attVal != ""){
document.getElementById("uploadButton"+attID).value = "Click Submit to upload";
document.getElementById("uploadButton"+attID).disabled = "true";
document.getElementById(attID).visible = "false";
if(pCount > 2){
var i = pCount - 1;
document.getElementById("textCount").value = i;
}
}
}
</script>
<div style="background-color:#eaeef0; width:98%; margin-left:5%; padding: 5% 5%;">
<div class = "text-center" id = "msg"></div>
</br>
<p style="background-color:#b7d3e1; width:100%; height:50px; padding:5px 5px; text-align:center;font-size:25px;">Create question or Tutorial</p> </br>
<label><input type="checkbox" id = "checkboxIns" value="tutorial" onclick = "checkboxIns();" >Tutorial</label> <div id = "tutorialCheck" style = "color: red;"></div>
</br>
<input type = "hidden" id = "memberID" value = "<?php echo $studentSessionDetails['id'];?>">
<label><h3>Due:</h3></label> </br>
<input type = "datetime-local" name= "duedate" > </br>
<label><h3>Title:</h3></label> </br>
<textarea id = "questionItself" class="form-control" rows="1" id="comment"></textarea>
<div id = "questionNotification" style = "color: red;">
Do not post private information in a question (e.g. real name, credentials) . Send it directly to the teacher doing your homework later on
</div>
</br>
<label><h3>Description:</h3></label></br>
<textarea name = "homework" id='TypeHere' required = "required"></textarea>
</br>
<label><input type="checkbox" id = "emailcheck" value="emailnotification" >Yes</label> <div>Would you like to receive notifications by email when writers post answers to your question?</div>
</br>
<label><h3>Attachments:</h3></label>
<div class = "form-inline">
<form method="post" action = "fileUploadhomeWork.php" enctype="multipart/form-data" class = "form-inline" target = "iframe">
<div id = "parentImageDiv">
Select file to upload
<div class = "form-group">
<input type="file" name="fileToUpload1" id="1">
</div><div class = "form-group"><input type="submit" value="Upload File(s)" name="submit" class = "btn btn-primary" id = "uploadButton1" onClick = "tempSave('1')">
</div>
</div>
</div>
<input type = "hidden" name = "textCount" id = "textCount" value = "1">
<input type = "hidden" name = "fileUploadFolder" value = "homeworkpost">
<input type = "button" value = "Add Another" onClick = "appendChildtoParent();"/>
</br></br>
<label>Homework Field of study</label></br>
<?php
$query = "SELECT categoryname FROM categories";
$statement = $db->_conn->prepare($query);
?>
<select id = "categories" class = "form-control" name = "categories">
<option value="">--- Please select ---</option>
<?php
try{
$statement->execute();
if($statement->rowCount()){
while($r = $statement->fetch(PDO::FETCH_OBJ)){
?>
<option value="<?php echo $r->categoryname;?>"><?php echo $r->categoryname;?></option>
<?php
}
}
else{
?>
<option value="">--- No available category ---</option>
<?php
}
}
catch(PDOException $e){
echo $e->getMessage();
}
?>
</select>
</br>
<label>I am willing to pay</label>
<input type="text" class="form-control" id="amountText">
<input style = "visibility: hidden;" type = "submit" name = "filesUploadBTN" id = "filesUploadBTN" style = "visible: hidden;"/></br>
<input class = "btn btn-default" type = "button" id = "BTNPostHomework" name = "BTNPostHomework" value = "Submit" onClick = "postHomework();"/>
<input class = "btn btn-default" type = "submit" id = "BTNPreviewHomework" name = "BTNPreviewHomework" value = "Preview"/>
</form>
</br>
<iframe style = "visibility: hidden;" name = "iframe"></iframe>
<!-- </form> -->
</br>
</div>
<!-- </div> -->
<?php
}
?>
您在'var vars'中沒有'duedate'。 – Barmar