Php MYSQL数据库中的数据未显示
我试图从mysql数据库中检索数据,但它不会显示在我的页面中。我想在我的“caption”类下显示数据库中的文本和图像。我知道这与我的css无关,因为当我删除css时,它们仍然什么都没有。数据库本身可能有问题吗Php MYSQL数据库中的数据未显示,php,html,mysql,Php,Html,Mysql,我试图从mysql数据库中检索数据,但它不会显示在我的页面中。我想在我的“caption”类下显示数据库中的文本和图像。我知道这与我的css无关,因为当我删除css时,它们仍然什么都没有。数据库本身可能有问题吗 <?php session_start(); $connect = mysqli_connect("localhost", "root", "root", "iphone"); ?> <!DOCTYPE html> <html> <hea
<?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>
将其放入数据库文件中 在产品中插入(
id
,p\u name
,image
,price
)值
(54,'sodfgjhpoifunf','images/ambient music.jpg',75.00)
在您的查询“从产品中选择*”中,您是否检查错误?
$result
是结果对象吗?你应该只标记相关的语言,例如,因为你排除了CSS,所以不要标记它。你不检查错误。您的脚本非常开放,甚至可以在MYSQLI
或PDO
API的sF12、inspect页面中使用?var_转储结果,有什么吗?在mysql控制台中手动运行查询,有什么问题吗?确定@SystemGlitchmysqli.*
非常活跃和安全,可能我没有收到备忘录,可能是行require'header.php'
正在停止脚本,因为它失败了,所以我想询问您是否在php.ini中启用了错误报告
,以查看它是否在该行上抛出警告。
-- 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);