2014-01-11 4 views
0

crud를 사용하여 데이터베이스에서 모든 행을 삭제하려고하는데 내 응답 삭제 페이지입니다. 쿼리 삭제 *를 시도했지만 작동하지 않아 수동으로 입력했습니다. 값은 미확인 색인으로 올라갑니다. 누구든지 도와 드릴까요, 내가 뭘 잘못하고 있는지 말해 주시고 더 쉬운 방법을 알려주십시오.crud 모든 행을 삭제하십시오.

<?php 
include "library.php"; 
include "database.php"; 
?> 


<?php 
//Get data from form 
$faculty=$_POST["faculty"]; 
$date=$_POST["date"]; 
$modulecode=$_POST["modulecode"]; 
$moduletitle=$_POST["moduletitle"]; 
$school=$_POST["school"]; 
$modulebookcontent=$_POST["modulebookcontent"]; 
$moduleorganisation=$_POST["moduleorganisation"]; 
$lrcmaterials=$_POST["lrcmaterials"]; 
$moduledifficulty=$_POST["moduledifficulty"]; 
$modulesimilarity=$_POST["modulesimilarity"]; 
$contentinteresting=$_POST["contentinteresting"]; 
$previousknowledge=$_POST["previousknowledge"]; 
$understoodassessmentrequirements=$_POST["understoodassessmentrequirements"]; 
$assessmentmethod=$_POST["assessmentmethod"]; 
$markedwork=$_POST["markedwork"]; 
$ML_interestforsubject=$_POST["ML_interestforsubject"]; 
$ML_contentclear=$_POST["ML_contentclear"]; 
$ML_appropriateteachingpace=$_POST["ML_appropriateteachingpace"]; 
$ML_reachableforadvice=$_POST["ML_reachableforadvice"]; 
$ML_helpfulfeedback=$_POST["ML_helpfulfeedback"]; 
$L1_interestforsubject=$_POST["L1_interestforsubject"]; 
$L1_contentclear=$_POST["L1_contentclear"]; 
$L1_appropriateteachingpace=$_POST["L1_appropriateteachingpace"]; 
$L1_reachableforadvice=$_POST["L1_reachableforadvice"]; 
$L1_helpfulfeedback=$_POST["L1_helpfulfeedback"]; 
$L2_interestforsubject=$_POST["L2_interestforsubject"]; 
$L2_contentclear=$_POST["L2_contentclear"]; 
$L2_appropriateteachingpace=$_POST["L2_appropriateteachingpace"]; 
$L2_reachableforadvice=$_POST["L2_reachableforadvice"]; 
$L2_helpfulfeedback=$_POST["L2_helpfulfeedback"]; 
$moduleleader=$_POST["moduleleader"]; 
$lecturer1=$_POST["lecturer1"]; 
$lecturer2=$_POST["lecturer2"]; 
$indpstudy=$_POST["indpstudy"]; 
$attendance=$_POST["attendance"]; 
$bestfeatures=$_POST["bestfeatures"]; 
$improvemodule=$_POST["improvemodule"]; 


$queryString = "delete from studentanswers where faculty=".$faculty; 
$queryString = "delete from studentanswers where date=".$date; 
$queryString = "delete from studentanswers where modulecode=".$modulecode; 
$queryString = "delete from studentanswers where moduletitle=".$moduletitle; 
$queryString = "delete from studentanswers where school=".$school; 
$queryString = "delete from studentanswers where modulebookcontent=".$modulebookcontent; 
$queryString = "delete from studentanswers where moduleorganisation=".$moduleorganisation; 
$queryString = "delete from studentanswers where lrcmaterials=".$lrcmaterials; 
$queryString = "delete from studentanswers where moduledifficulty=".$moduledifficulty; 
$queryString = "delete from studentanswers where modulesimilarity=".$modulesimilarity; 
$queryString = "delete from studentanswers where contentinteresting=".$contentinteresting; 
$queryString = "delete from studentanswers where previousknowledge=".$previousknowledge; 
$queryString = "delete from studentanswers where understoodassessmentrequirements=".$understoodassessmentrequirements; 
$queryString = "delete from studentanswers where assessmentmethod=".$assessmentmethod; 
$queryString = "delete from studentanswers where markedwork=".$markedwork; 
$queryString = "delete from studentanswers where ML_interestforsubject=".$ML_interestforsubject; 
$queryString = "delete from studentanswers where ML_contentclear=".$ML_contentclear; 
$queryString = "delete from studentanswers where ML_appropriateteachingpace=".$ML_appropriateteachingpace; 
$queryString = "delete from studentanswers where ML_reachableforadvice=".$ML_reachableforadvice; 
$queryString = "delete from studentanswers where ML_helpfulfeedback=".$ML_helpfulfeedback; 
$queryString = "delete from studentanswers where L1_interestforsubject=".$L1_interestforsubject; 
$queryString = "delete from studentanswers where L1_contentclear=".$L1_contentclear; 
$queryString = "delete from studentanswers where L1_appropriateteachingpace=".$L1_appropriateteachingpace; 
$queryString = "delete from studentanswers where L1_reachableforadvice=".$L1_reachableforadvice; 
$queryString = "delete from studentanswers where L1_helpfulfeedback=".$L1_helpfulfeedback; 
$queryString = "delete from studentanswers where L2_interestforsubject=".$L2_interestforsubject; 
$queryString = "delete from studentanswers where L2_contentclear=".$L2_contentclear; 
$queryString = "delete from studentanswers where L2_appropriateteachingpace=".$L2_appropriateteachingpace; 
$queryString = "delete from studentanswers where L2_reachableforadvice=".$L2_reachableforadvice; 
$queryString = "delete from studentanswers where L2_helpfulfeedback=".$L2_helpfulfeedback; 
$queryString = "delete from studentanswers where moduleleader=".$moduleleader; 
$queryString = "delete from studentanswers where lecturer1=".$lecturer1; 
$queryString = "delete from studentanswers where lecturer2=".$lecturer2; 
$queryString = "delete from studentanswers where indpstudy=".$indpstudy; 
$queryString = "delete from studentanswers where attendance=".$attendance; 
$queryString = "delete from studentanswers where bestfeatures=".$bestfeatures; 
$queryString = "delete from studentanswers where improvemodule=".$improvemodule; 


queryDatabase($queryString); 
?> 


<?php CRUDheader("Delete Student Answers"); ?> 

<body> 

<div id="main"> 

<div id="content"> 
<p>Student answers deleted</p> 
</div> 

</div><?php CRUDmain(); ?> 

</body> 
</html> 
+1

왜 'TRUNCATE TABLE studentanswers'를 사용하지 않으시겠습니까? 삭제할 특정 행을 선택했다면 올바른 구문은 'DELETE FROM studentanswers WHERE column1 = value1'입니다. – Mave

+0

'delete * from'은 유효한 SQL 구문이 아닙니다. 개별 필드를 삭제할 수 없으므로 삭제는 필드 목록을 허용하지 않습니다. 전체 행만 삭제할 수 있습니다. 즉, 모든 필드가 삭제된다는 의미입니다. 'delete from table'은 적절한 문법입니다. –

+0

@Mave는 행이나 테이블을 잘라 버릴까요? 미안 해요, 이거 처음이에요. – taniakeira

답변

0

당신이 훨씬 더 힘들게 만든 것처럼 보입니다.

@Mave가 제안했듯이 간단히 TRUNCATE TABLE studentanswers 일 수 있습니다.

은 삭제와 함께하고 싶은 가정하면, delete *에 가까웠다하지만 그것을 언급하는 올바른 방법이 아니다 :

DELETE FROM STUDENTANSWERS 

트릭을 할 것입니다. 당신이 WHERE을 포함 미리 구성된 쿼리 입력의 어떤 종류가 있다면

당신은

DELETE FROM STUDENTANSWERS WHERE 1=1 

모든 행을 삭제 할 수 있습니다.

0

실행중인 유일한 쿼리는 queryDatabase ($ queryString) 전에 할당 된 마지막 쿼리입니다. 당신은 $ queryString = "delete ..."를 끝내기 전에 마지막 코드와 똑같은 일을 할 수 있습니다.

기능적으로,이 같은 일을하고있다 :

돌아 가기
$queryString = "A"; //This does nothing because $queryString gets reset on the next line 
$queryString = "B"; //This does nothing because $queryString gets reset on the next line 
$queryString = "C"; //This does nothing because $queryString gets reset on the next line 
$queryString = "delete from studentanswers where improvemodule=".$improvemodule; 
queryDatabase($queryString); 

질문에. 모든 행을 삭제하려면 다음을 수행하십시오.

$queryString = "delete from studentanswers where 1=1; 
queryDatabase($queryString); 
관련 문제