Mysql/Php-显示从列表中选择的单个产品页面

Mysql/Php-显示从列表中选择的单个产品页面,php,mysql,Php,Mysql,我有一个PHP页面,它是下面描述的产品列表。最后一列是指向单一产品页面的链接,该页面报告了该产品的所有详细信息 ID | Title | LINKTOPAGE -------|--------------|------------------ 001 | ProductTitle | $ID(001)-->Link to the single_product_page.php 002 | ProductTitle | $ID(002)-->Lin

我有一个PHP页面,它是下面描述的产品列表。最后一列是指向单一产品页面的链接,该页面报告了该产品的所有详细信息

ID     |   Title      |   LINKTOPAGE
-------|--------------|------------------
001    | ProductTitle | $ID(001)-->Link to the single_product_page.php
002    | ProductTitle | $ID(002)-->Link to the single_product_page.php
003    | ProductTitle | $ID(003)-->Link to the single_product_page.php
上表由以下循环生成:

 <?php
          while ($row = mysqli_fetch_array($risultato)){
               echo '<tr>
                         <td>'.$row['id'].'</td>
                         <td>'.$row['post_title'].'</td>
                         <td>'.'LinkToSinglePage >>'.'</td> 
                    </tr>';
          }?>
我试图做的是将“linktoProductPaGe”链接到单个页面。如果我没有错,我应该用在列表中存储所选产品ID的变量替换ID=13323


有什么建议吗?

您可以这样做,例如(get方法):

产品列表(products_lists.php):


在产品详细信息页面(single_product_page.php)中,您可以获得如下id:

<?php $product_id = $_GET['product_id']; ?>


希望这会有所帮助。:-)

要避免在从浏览器打开页面single_product_page.php时出现语法错误,应添加以下代码:

if(!isset($_GET['product_id']){ 
    echo 'No product selected.'; 
}else{ 
   // Your code to get the product infos 
}

这可能是因为HTML表单的标记“action”未定义或值为“singolo_prodotto.php”

因此,在页面“singolo_prodotto.PHP”的PHP代码开头,您应该添加以下代码,如下所述:

if(!isset($_GET['product_id']){ 
   echo 'No product selected.'; 
}else{ 
   // Your code to get the product infos 
}
当您必须管理产品的版本时,您必须添加另一个类似的条件:

if(!isset($_GET['a_field_of_your_html_form']){ // Or "$_POST['a_field_of_your_html_form']"
   // Your product edition code 
}

是的,您需要使用准备好的语句,还需要使用表示post ID的变量。Tim,我错过的是如何将products_lists.php的变量(ID product)传递到single_product_page.php的p.ID中,替换为示例“13323”。基本上,最后一列中的链接应该捕获第一列中的ID,移动到single_product_page.php,将ID替换到查询中并执行它。继续尝试Rafael。您应该使用例如PDO的SQL查询来防止SQL注入。;-)对我来说不容易,但我会尝试。第一部分没问题,让我看看目标页面。“其中p.ID=$product\u ID”在另一部分中,我将包括我用来检索信息的sql查询,对吗?问题是定位在单个产品页面的字段中并按下ENTER键,脚本找不到$product\u id变量,并向我提供此错误:-->“注意:未定义索引:第7行的/Applications/XAMPP/xamppfiles/htdocs/gest/pages/singolo_prodotto.php中的product_id查询无效数据:您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以了解在第22行的“按p.ID联合分组全部选择ps.ID,ps.post_title,ps.post”附近使用的正确语法
if(!isset($_GET['product_id']){ 
   echo 'No product selected.'; 
}else{ 
   // Your code to get the product infos 
}
if(!isset($_GET['a_field_of_your_html_form']){ // Or "$_POST['a_field_of_your_html_form']"
   // Your product edition code 
}