나는 등록 된 사용자가 로그인하여 메모를 작성할 수있는 웹 응용 프로그램을 만들고 있습니다. 이제는 "X"를 클릭하여 특정 쪽지를 삭제하는 함수를 추가하고 싶습니다. 그러나이 경우에 생성 된 특정 노트를 식별 할 수있는 방법을 실제로 파악할 수는 없습니다 메서드, 더 정확하게, 어떻게 그 id를 삭제 쿼리에 사용할 반환 할 수 있습니다. 다음은 지금 보이는 모습을 확인할 수있는 사이트입니다. 아래에 댓글을 적어 놓은 방법을 첨부 해 드리겠습니다. 미리 감사드립니다!ID가 할당되지 않은 상태에서 메모를 삭제하는 방법이 있습니까?
http://laszlovaszi.com/mx_agency/index.php
<?php
function confirm_query($result) {
\t if (!$result) {
\t \t die("Database query failed.");
\t }
}
function find_notes_by_id($user_id) {
\t global $connection;
\t $row = array();
\t
\t $safe_user_id = mysqli_real_escape_string($connection, $user_id);
\t
\t $query = 'SELECT content ';
\t $query .= 'FROM notes ';
\t $query .= 'WHERE user_id = '.$safe_user_id;
\t $result = mysqli_query($connection, $query);
\t
\t confirm_query($result);
\t
\t $final_data = array();
while($row = mysqli_fetch_assoc($result)){ // iterates over the result-set object to get all data
$final_data[] = $row; //assigns value to the array
}
\t return $final_data;
}
?>
<div class="notes text-center">
\t \t \t \t \t <?php
\t \t \t \t \t $notes_set = find_notes_by_id($userRow['id']);
\t \t \t \t \t if(empty($notes_set)){
\t \t \t \t \t \t echo "No notes have been posted for this user yet.";
\t \t \t \t \t } else {
\t \t \t \t \t \t echo "<div class=\"notelist text-left\">";
\t \t \t \t \t \t foreach($notes_set as $note){
\t \t \t \t \t \t \t echo "<div class=\"note text-left\">";
\t \t \t \t \t \t \t echo "● ";
\t \t \t \t \t \t \t echo htmlentities($note['content']);
\t \t \t \t \t \t \t echo "<br />";
\t \t \t \t \t \t \t echo "</div>";
\t \t \t \t \t \t }
\t \t \t \t \t \t echo "</div>";
\t \t \t \t \t }
\t \t \t \t \t ?>
</div>
경고 ** ** mysql을 사용할 때 [매개 변수가있는 쿼리] (http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)와 ['bind_param' ] (http://php.net/manual/en/mysqli-stmt.bind-param.php)를 사용하여 쿼리에 사용자 데이터를 추가하십시오. ** 올바르게 이스케이프하는 것을 잊어 버린 경우 심각한 [SQL injection bug] (http://bobby-tables.com/)를 만들 것이므로 수동 이스 케이 핑 및 문자열 보간 또는 연결을 사용하지 마십시오. – tadman
천천히 자신의 ORM을 쓰고있는 것처럼 보입니다. [Doctrine] (http://www.doctrine-project.org/) 또는 [Propel] (http://propelorm.org/)과 같은 기존의 것을 사용해 보셨습니까? – tadman
메모가 내 물건이라는 뜻입니까? - 미안 해요. 초보자 일뿐입니다. 처음에는 자신을 모두 "하드 코드"하는 법을 배우는 것이 더 스마트하다고 생각했기 때문에 두 가지 중 어느 것도 고려하지 않았습니다. 그것은 기본에서 작동합니다. – sklrboy