2013-12-16 2 views
-1

어디서나 검색했지만 답변을 찾을 수 없지만 올바른 코드가 있다고 생각되지만 오타가있을 수 있습니다.PHP MySQL 행 삭제

여기에 무슨 문제가 있습니까?

나는 링크가 그 게시물과 같이 URL에 올바르게 제품 ID :

userAccount.php :

while($columnDelete = mysqli_fetch_array($query, MYSQLI_ASSOC)){ 
     echo "<section class='product'> 
       <a href='extras/deleteProcess.php?productId=".$columnDelete['productId']."' class='deleteProduct' style='color:#990000;font-family:arial;font-weight:bold;font-size:12pt;background:transparent;'>Delete?</a> 
       <section class='productImg'> 
        <a target='_self' href='fullProductInfo.php?productId=".$columnDelete['productId']."'> 
         <img src='http://www.littlepenguindesigns.co.uk/pages/CMX/images/products/".$columnDelete['productImg']."' alt='".$columnDelete['productName']."' border='0' width='230' height='200' border='0' /> 
        </a> 
       </section> 
       <section class='productName'><a target='_self' href='fullProductInfo.php?productId=".$columnDelete['productId']."'>".$columnDelete['productName']."</a></section> 
       <section class='productPrice'>&pound;".$columnDelete['price']."</section></section>"; 
    } 

$columnDelete['productId'];가 URL에 올바른 ID를 게시하고, 내가 수있는 deleteProcess.php 페이지

deleteProcess.php :

01이 표시됩니까, URL에 productId을보고 나는 또한 확인하기 위해 페이지에 그것을 에코있다
$productId = $_GET['productId']; 
$con = mysqli_connect("BLAH","BLAH","BLAH","BLAH") or die('Server connection not possible.'); 
$sql = ("DELETE FROM `product` WHERE `product`.`productId`= $productId"); 
mysqli_query($con, $sql); 

echo "Deleted product ID: $productId successfully.<br /><br /><br /><br /><br /><br /> <a href='../userAccount.php#deletion'>Go back to user account and delete another.</a>"; 

나는 무슨 일이 벌어지고 있는지, 제품이 deleteProcess.php으로 호출되어 페이지로 옮겨 지지만 삭제되지는 않지만 오류가 없음을 보여줍니다. 내가 php와 mysql에 익숙해 졌을 때 나는 최고의 연구를 할 것이라고 생각했다. 나는 물어볼 생각이 없었기 때문에 누구나 내가 잘못하고있는 것을 나에게 가르쳐 줄 수있다.

+0

체크하면 –

+0

쿼리를 에코 다음 phpMyAdmin을 직접 실행 한 후 오류가 원하든 참조 –

답변

0
$sql = ("DELETE FROM `product` WHERE `product`.`productId`= $productId"); 
mysqli_query($con,$sql); 

$sql = "DELETE FROM `product` WHERE `product`.`productId`= $productId"; 
mysqli_query($con,$sql) OR DIE(mysqli_error($con)); //useful for debugging 

경고에!이 코드는 SQL 삽입에 취약합니다. 모든 사용자 입력을 삭제하여 sql injection을 수정합니다. MySQL의 연결 여부를

$productId = mysql_real_escape_string($_GET['productId']); // use mysql_real_escape_string on $_GET 
$con = mysqli_connect("BLAH","BLAH","BLAH","BLAH") or die('Server connection not possible.'); 
$sql = "DELETE FROM `product` WHERE `product`.`productId`= '$productId'"; //add single quotes around variable $productid to seperate string from query 
mysqli_query($con, $sql); 
0

확인 쿼리 실행 복귀 성공 여부

$productId = $_GET['productId']; 
$con = mysqli_connect("BLAH","BLAH","BLAH","BLAH") or die('Server connection not possible.'); 
$sql = ("DELETE FROM `product` WHERE `product`.`productId`= $productId"); 

$result = mysqli_query($con, $sql); 
if(!$result) 
    die("Query failed".mysql_error()); 

echo "Deleted product ID: $productId successfully.<br /><br /><br /><br /><br /><br /> <a href='../userAccount.php#deletion'>Go back to user account and delete another.</a>";