Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP MySQL删除行_Php_Mysql_Delete Row_Corresponding Records - Fatal编程技术网

PHP MySQL删除行

PHP MySQL删除行,php,mysql,delete-row,corresponding-records,Php,Mysql,Delete Row,Corresponding Records,我到处都找遍了,找不到答案,我相信我有正确的代码,但可能是打字错误 这里出了什么问题 我有一个将产品id正确发布到url的链接,如图所示: userAccount.php: while($columnDelete = mysqli_fetch_array($query, MYSQLI_ASSOC)){ echo "<section class='product'> <a href='extras/deleteProcess.php

我到处都找遍了,找不到答案,我相信我有正确的代码,但可能是打字错误

这里出了什么问题

我有一个将产品id正确发布到url的链接,如图所示:

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>";
    }
$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还不熟悉,所以我认为我最好进行研究,因为我没有找到我想问的答案,所以谁能告诉我我做错了什么,或者给我指出了正确的方向。

检查查询执行返回成功与否

$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>";
$productId=$\u GET['productId'];
$con=mysqli_connect(“废话”、“废话”、“废话”、“废话”)或die(“服务器连接不可能”);
$sql=(“从`product`中删除,其中`product`.`productId`=$productId”);
$result=mysqli\u查询($con,$sql);
如果(!$result)
die(“查询失败”。mysql_error());
echo“已删除产品ID:$productId成功。





警告此代码易受SQL注入攻击。 通过清理所有用户输入修复sql注入

$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);

检查mysql是否连接或notecho查询,然后直接运行到phpmyadmin中,然后查看错误是什么
$sql = "DELETE FROM `product` WHERE `product`.`productId`= $productId";
mysqli_query($con,$sql) OR DIE(mysqli_error($con)); //useful for debugging
$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);