0

我目前正在进行实时搜索,效果很好,当人们看到实时搜索的结果时,会出现“编辑、删除和查看”三个链接

当我试图通过单击删除链接从数据库中删除一个产品信息时,但问题是它没有做任何事情,甚至根本没有显示错误......

我显示 url 地址末尾没有 product_id 编号查看完整的 url ...

http://localhost/shopone/admin/live/search-save.php?deleteid=

我在代码中错过了什么?

本部分用于从搜索文本字段中获取结果。

<?php
if(isset($_POST['kw']) && $_POST['kw'] != '')
{
  $kws = $_POST['kw'];
  $kws = mysql_real_escape_string($kws); 
  $query = "select * from product where product_name like '%".$kws."%' limit 10" ;
  $res = mysql_query($query);
  $count = mysql_num_rows($res);
  $i = 0;
  if($count > 0)
  {
    while($row = mysql_fetch_array($res))
    {
    $product_id = $row["product_id"];

    //Contanter     
    echo "  <div class='container'>";

    //First columns Product Images
    echo "<div class='sidebar1'>";
    echo "<div>";?><a href='$row[$product_name]'><img src="<?php echo $row["screenshot"];?>" width="100" height="100" /></a> 
    <?php echo "</div>" ; 
    echo "</div>";

    //Second columns Product Name
    echo "<div class='content'>";
    echo $row['product_name'];"</div>";
    echo "</div>";

    //3rd columns Product Category
    echo "<div class='sidebar2'>";
    echo $row['product_category'];
    echo "</div>";

    //Fourth columns Product Retail Price
    echo "<div class='sidebar3'>";
    echo $row['product_retail_price'];
    echo "</div>";

    //Fifth columns Product Price
    echo "<div class='sidebar4'>";
    echo $row['product_price'];
    echo "</div>";
    //Sixth columns Product Price
    echo "<div class='sidebar4'>";
    echo "<a href='../data/edit_product.php?pid=' . $product_id . ''>Edit</a> &nbsp;&nbsp;
    <a href='search-save.php?deleteid=' . $product_id . ''>Delete</a>&nbsp;&nbsp;
    <a href='../data/edit-view.php?pid=' . $product_id . ''>View</a>";

    echo "</div>";

    //End of Container
    echo "</div>";

      $i++;
      if($i == 5) break;
    }
    echo "</ul>";
    if($count > 5)
    {
      echo "<div id='view_more'><a href='#'>View more results</a></div>";
    }
  }
  else
  {
    echo "<div id='no_result'>No result found !</div>";
  }
}
?>

此部分用于按删除时删除....

<?php
  //Delete Item Question to Admin, and Delete Product if they choose
  if (isset($_GET['deleteid'])) {
     echo 'Do you really want to delete product with ID of ' . $_GET['deleteid'] . '? <a href="search-save.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="search-save.php">No</a>';
    exit();
  }
 if (isset($_GET['yesdelete'])) {
//remove item from system and delete its picture
//delete from database
    $id_to_delete = $_GET['yesdelete'];

    $sql = mysql_query("DELETE FROM product WHERE product_id='$id_to_delete' LIMIT 1") or die (mysql_error());
/////////////////////////////////////////////////////////////
// unlink the image from server
// Remove The Pic -------------------------------------------
/////////////////////////////////////////////////////////////

    $pictodelete = ("../product_images/$id_to_delete.jpg");

    if (file_exists($pictodelete)) {
                unlink($pictodelete);
    }
}
?>
4

1 回答 1

1

你的这条线

<a href='$row[$product_name]'>

使用 php 标签是错误的,虽然问题不是由于这个,而是由于下一行

echo "<a href='../data/edit_product.php?pid=' . $product_id . ''>Edit</a> &nbsp;&nbsp;
<a href='search-save.php?deleteid=' . $product_id . ''>Delete</a>&nbsp;&nbsp;
<a href='../data/edit-view.php?pid=' . $product_id . ''>View</a>";

当你检查你的html时,你会得到这个

<a href="../data/edit_product.php?pid=" .="" 2="" ''="">Edit</a> &nbsp;&nbsp;
<a href="search-save.php?deleteid=" .="" 2="" ''="">Delete</a>&nbsp;&nbsp;
<a href="../data/edit-view.php?pid=" .="" 2="" ''="">View</a>

假设产品 id 是 2。所以它不起作用。

将php代码更改为

 echo '<a href="../data/edit_product.php?pid='. $product_id . '">Edit</a> &nbsp;&nbsp;
<a href="search-save.php?deleteid=' . $product_id . '">Delete</a>&nbsp;&nbsp;
<a href="../data/edit-view.php?pid=' . $product_id . '">View</a>';
于 2013-10-24T05:14:58.033 回答