PHP를 사용하여 SQL 데이터베이스의 행을 삭제하려고합니다. 행은 사용자 유형에 제품의 이름에 의해 결정됩니다 SQL + AJAX + PHP POST 요청
가 이미 입력 된 제품 삭제하는 간단한 양식을 작성 :.<article>
<section>
<fieldset><legend><span>Would you like to add a Product?</span> </legend>
<form method="POST" id = "myForm" name="myForm" onsubmit="return false;">
<br>
<p>Enter a name of product <input type='text' id='name' name = 'name'/></p>
<br>
<input name="submit" id ="submit" type="button" value="Find Product"/>
</form>
</fieldset>
<div id="fetchProduct">
</div>
</section>
</article>
가 이미 데이터를 입력 한 말을 다른 양식에 그것은 데이터베이스에 들어가지만 내가 그것을 삭제하려고하면 삭제하려고하면 정의되지 않은 색인 : 이름 오류가 발생합니다. 여기
제품을 삭제할 사용하여 스크립트 메신저입니다 :
<?php
include("database/connect_database.php");
$name = $_POST['name'];
$query = "DELETE FROM products WHERE product_name = '$name' ";
$result = $database->query($query) OR die ("Failed query $query");
echo $database->error."<p>";
if($result){
echo "Record deleted";
}
else {
echo "Product not found!";
}
?>
임은 또한 이름을 통과 AJAX를 사용하여
: 메신저 여기 때문에 끔찍하게 잘못가는 곳
fetch = function() {
// declare the two variables that will be used
var xhr, target, changeListener;
// find the element that should be updated
target = document.getElementById("fetchProduct");
var name = document.getElementById("name").value;
var variable = "name="+name;
// create a request object
xhr = new XMLHttpRequest();
changeListener = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
target.innerHTML = xhr.responseText;
} else {
target.innerHTML = "<p>Something went wrong.</p>";
}
};
xhr.open("POST", "deleteProductSQL.php", true);
xhr.onreadystatechange = changeListener;
xhr.send(variable);
};
pageLoaded = function() {
var fetchButton = document.getElementById("submit");
if (fetchButton) {
fetchButton.addEventListener("click", fetch);
}
};
window.onload = pageLoaded;
누구든지 지적 할 수 왜 내가 행을 삭제할 수 없으며 왜 정의되지 않은 오류가 발생하는지 알 수없는 이유를 파악할 수 없습니다. 는 isset에 PHP 코드를 넣어
멋진 [SQL 주입 공격] (http://bobby-tables.com) 취약점. 서버 pwn3d를 가지고 즐기십시오. –