我正在尝试从我的mysql数据库中检索数据,但它不会显示在我的页面中。我想在我的“标题”类下面显示我的数据库中的文本和图像。我知道这与我的css无关,考虑到当我删除我的CSS时,他们仍然没有任何东西。数据库本身可能有问题吗?
<?php
session_start();
$connect = mysqli_connect("localhost", "root", "root", "iphone");
?>
<!DOCTYPE html>
<html>
<head>
<title>Starter Project</title>
<meta charset="utf-8">
<title>HTML5 Audio</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="audio.css">
<link rel="stylesheet" href="ism/css/my-slider.css"/>
<link rel="stylesheet" href="imagehover.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<?php
require'header.php';
?>
<?php
$query = "SELECT * FROM products ORDER BY id ASC";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<div class="content">
<div class="caption">
<img src="<?php echo $row["image"]; ?>" class="caption__media">
<div class="caption__overlay">
<div class="overlay-text-padding">
<h5 class="caption__overlay__title"><?php echo $row["p_name"]; ?></h5>
<h5 class="text-danger">$ <?php echo $row["price"]; ?></h5>
<p class="caption__overlay__content"></p>
<form class="addToCart" action="index.php?action=add&id=<?php echo $row["id"]; ?>" method="post">
<input type="hidden" name="quantity" class="form-control" value="1">
<input type="hidden" name="hidden_name" value="<?php echo $row["p_name"]; ?>">
<input type="hidden" name="hidden_price" value="<?php echo $row["price"]; ?>">
<form action="/my/link/location" method="get">
<input type="submit" value="<?php echo $row["link"]; ?>" name="Submit" id="frm1_submit"/>
</form>
</form></div></div></div></div>
<?php
}
}
?>
<!---push menu stuff below stays on bottom-->
<?php
include'pushmenu.php';
require'pushmenu.php';
?>
</div>
</main>
</body>
</html>
数据库代码:
-- Host: localhost
-- Generation Time: Apr 19, 2018 at 11:58 AM
-- Server version: 5.6.38
-- PHP Version: 7.2.1
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `iphone`
-- Table structure for table `products`
CREATE TABLE `products` (
`id` int(11) NOT NULL,
`p_name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` double(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `products`
--
INSERT INTO `products` (`id`, `p_name`, `image`, `price`) VALUES
(54, 'sodfgjhpoifunf', 'images/ambient music.jpg', 75.00);
答案 0 :(得分:-1)
将它放在您的数据库文件中
INSERT INTO产品(id
,p_name
,image
,price
)价值观
(54,'sodfgjhpoifunf','images / ambient music.jpg',75.00);
并在您的查询“SELECT * FROM products”
中