【问题标题】:Images and product info not showing up on page图片和产品信息未显示在页面上
【发布时间】:2018-07-30 04:07:24
【问题描述】:

一直在为我妻子的珠宝网站制作产品页面。我从教程中添加了 php 并尝试运行该页面。包括页眉在内的所有图像都没有与页脚一起出现。它们出现在每隔一页上。信息产品也没有出现。该页面显示连接已打开,我没有收到任何错误。导航与一些 css 一起显示,但仅此而已。

这是我正在使用的代码。

       <?php 
        error_reporting(E_ALL);
        ini_set('display_startup_errors', 1);
        ini_set('display_errors', 1);
        ?>
        <?php 
        if (isset($_GET['id'])) {
            // Connect to the MySQL database  
            include_once("storescripts/connect_to_mysql.php");
            $con = 





              mysqli_connect("$db_host","$db_username","$db_pass","$db_name"); 

            if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_errno());
            exit();


        } $id = preg_replace('#[^0-9]#i', '', $_GET['id']); 
            $sql = "SELECT * FROM products WHERE category='Bracelets';";
            $result = mysqli_query($con, $sql);
            $resultCheck = mysqli_num_rows($result);
            if ($resultCheck > 0) {
                // get all the product details
                while($row = mysqli_fetch_assoc($result)); { 
                     $item_number = $row["item_number"];
                     $price = $row["price"];
                     $desc = $row["description"];
                     $category = $row["category"];
                 }

            } else {
                echo "Data to render this page is missing.";
                exit();
            }
        }
        ?>
        <!DOCTYPE html>
        <html>
        <head>
            <title>Bracelets</title>
            <meta charset="utf-8">
            <meta http-equiv="x=UA-comparable" content="IE-edge">
            <meta name="description" content="Pinky's Pearls is a website where 
            one 
            of a kind jewelry designed by Nichole <q>Nicki</q> can be seen and 
            purchased">
            <meta name="keywords" content="jewelry, beads, bracelets, rings, 
            pendants, necklaces, pearls, crystal">
            <meta name="viewpoint" content="width=device-width, initial-scale=1">
            <meta name="author" content="samuel jaycox">
            <link href="style.css" rel="stylesheet">
            <link rel="stylesheet" 
             href="https://cdnjs.cloudflare.com/ajax/libs/font- 
            awesome/4.7.0/css/font-awesome.min.css">
            <link rel="shortcut icon" type="image/png" href="pictures/pinky.png">
            <script src="https://use.fontawesome.com/0c9491c5b9.js"></script>
        </head>
        <body>
            <div align="center"  id="wrapper">
            <div id="banner-wrapper">
            <?php 



  include_once("c:/xampp/htdocs/pinkys_pearls/templates/template_bracelets.php"); 
            ?>
                <br>
            <?php include_once("templates/template_navigation.php"); ?>     
                <br>
                <br>
                <br>
        <!--Start Comment page Body Content-->
        <div id="body-content">
            <div class="bracelet_body">
                <table width="100%" border="2" cellspacing="0" cellpadding="15">
          <tr>
            <td width="19%" valign="top"><img src="pictures/inventory/<?php echo 
        $pid; ?>.png" width="142" height="188" alt="<?php echo $item_number; ?>" 
        /> 
       <br />
              <a href="pictures/inventory/<?php echo $pid; ?>.png">View Full Size 
        Image</a></td>
            <td width="81%" valign="top"><h3><?php echo $item_number; ?></h3>
              <p><?php echo "$".$price; ?><br />
                <br />
                <?php echo $desc; ?>
        <br />
                </p>
              <form  id="form1" name="form1" method="post" action="cart.php">
                <input type="hidden" name="pid" id="pid" value="<?php echo $id; ? 
         >" 
        />
                <input class="button" type="submit" name="button" id="button" 
       value="Add to Shopping Cart" />
              </form>
              </td>
            </tr>
        </table>
            </div>
        </div>
        <!--end of Comment body-->
        <?php include_once('templates/template_footer.php'); ?>">
        </body>
        </html>

【问题讨论】:

  • 你在 html 部分的哪里定义了$pid
  • 检查include_once 中的网址。它在同一个目录中吗?如果是,请不要使用像c:/xampp/htdocs 这样的网址,您的页脚在哪里,我看不到您在 HTML 中包含的任何页脚
  • 我昨晚在处理页脚部分时不小心取出了它。我重做了 php,页脚和导航出现了,但页眉仍然没有。它显示在 Dreamweaver 的查看器中。仍然无法获取产品信息。
  • $pid 是在将项目放入数据库时​​在 inventory_list 页面上定义的。它是图片id的变量。

标签: php html css mysqli


【解决方案1】:

请确保您的路径正确!

尝试更改链接

&lt;?php include_once("c:/xampp/htdocs/pinkys_pearls/templates/template_bracelets.php"); ?&gt;

&lt;?php include_once("c:/xampp/htdocs/pinkys_pearls/templates/template_navigation.php"); ?&gt;

作为

&lt;?php include_once("localhost/pinkys_pearls/templates/template_bracelets.php"); ?&gt;

&lt;?php include_once("localhost/pinkys_pearls/templates/template_navigation.php"); ?&gt;

并且确保您的图片路径,如果文件夹不同,您将无法加载图片。

【讨论】:

  • 我已经仔细检查了路径并重新编写了 php.ini 文件。我仍然没有从数据库中获取信息。换句话说,我需要来自行类别的所有信息以及手镯的价值。我的新 php 在顶部,
  • 嘿嗨,请在 crome 浏览器中使用检查元素,然后转到控制台选项卡菜单查看显示的错误。这将帮助你
  • 这是控制台所说的: [弃用] 其 URL 包含已删除的空白(\n、\r、\t)字符和小于字符(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-14
  • 2016-05-07
  • 2019-06-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多