2014-03-01 2 views
0

나는 레코드 목록을 가지고 있습니다. 나는 모든 레코드와 버튼을 삭제하고 $.ajax() 기능으로 레코드를 삭제하고 있습니다. 하지만 삭제 버튼을 클릭하면 데이터베이스에서 레코드가 삭제되지 않으며, 데이터를 경고하면 전체 HTML 페이지가 출력됩니다. 여기 코드가 있습니다. 도와주세요.

HTML 코드

<tbody> 
     <tr class="gradeX odd"> 
     <td class="sorting_1">2</td> 
     <td class=" ">test</td> 
     <td class=" ">test</td> 
     <td class="center ">0</td> 
     <td class="center ">Active</td> 
     <td class=" "><button type="button" class="btn btn-default btn-circle" name="editRecord"><i class="fa fa-pencil-square-o"></i></button> 
      <button type="button" class="btn btn-danger btn-default btn-circle" id="2" name="deleteRecord"><i class="fa fa-times"></i></button></td> 
     </tr> 
     <tr class="gradeX even"> 
     <td class="sorting_1">3</td> 
     <td class=" ">sarees</td> 
     <td class=" ">contains sarres</td> 
     <td cl="center ">1</td> 
     <td class="center ">Active</td> 
     <td class=" "><button type="button" class="btn btn-default btn-circle" name="editRecord"><i class="fa fa-pencil-square-o"></i></button> 
      <button type="button" class="btn btn-danger btn-default btn-circle" id="3" name="deleteRecord"><i class="fa fa-times"></i></button></td> 
     </tr> 

    </tbody> 

JQuery와

$(document.body).on('click', '[name="deleteRecord"]', function(){ 
    var id= $(this).attr('id'); 
    var parent = $(this).parent().parent(); 
     if (confirm("Are you sure you want to delete this row?")) 
     { 
     $.ajax({ 
        type: "GET", 
        url: "admin_operation.php?mode=delete_category&id="+id, 
        cache: false, 

        success: function(data) 
        { 
        alert(data); 
        parent.fadeOut('slow', function() {$(this).remove();}); 
        } 
      }); 
     } 
    }); 

PHP 코드 URL

$mode = $_GET['mode']; 

if($mode!='add_category' || $_GET['mode']!= "delete_category") 
{ 
    header('location:dashboard.php'); 
    die; 

    } 


    if($mode=='delete_category') 
    {  

     $id=$_GET['id']; 
     $q=$db->query("DELETE FROM db_category WHERE category_id='".$id."'"); 
     if($q){ echo "yes";} 
     else{ echo "no";} 

    } 
+7

여기에서하는 일은 * 정말로 * 위험합니다. 첫째, 누구나 그 URL을 통해 물건을 삭제할 수 있으며, 둘째로, 넓은 ope입니다. SQL 주입. – Marty

+0

@marty하지만 post 메서드를 사용하면 동일한 오류가 발생합니다. 나는 어떻게해야합니까? – user3288891

+1

'POST '는이 두 가지 중 하나를 방지하지 않습니다. – Marty

답변

0

보내 ': "admin_operation.p HP? PHP 스크립트에서 자바 스크립트 모드 = delete_category & ID = "+ ID '. 그리고, 당신은 헤더 및 종료 스크립트를 다시 조건을 가지고있다.

if($mode!='add_category' || $_GET['mode']!= "**delete_category**") 
{ 
    header('location:dashboard.php'); 
    die; 
} 

코드의 다음 블록

if($mode=='delete_category') 
{ 
    // ... 
} 

에 도달하지 않았습니다. 희망이 해결책으로 도움이됩니다.

+0

tnx .. 대신 ||이어야합니다. if ($ mode! = 'add_category'&& | $ _GET [ 'mode']! = "** delete_category **") – user3288891

관련 문제