0

I'm trying to retrieve data from my mysql database but it wont show in my page. I want to display the text and Images I have within my database right under my "caption" class. I know it has nothing to do with my css considering when I remove my css their is still nothing there. Could there be something wrong with the database itself?

 <?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>

The Database code:

-- 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);
chris85
  • 23,846
  • 7
  • 34
  • 51
  • Are you checking for errors? Is `$result` a result object? You should only tag relevant languages, e.g. since you ruled out CSS don't tag it. – chris85 Apr 19 '18 at 16:59
  • 1
    Yo uare not checking for errors. Your script is wide open to [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) in either the `MYSQLI_` or `PDO` API's – RiggsFolly Apr 19 '18 at 16:59
  • 1
    F12, inspect page, anything there? var_dump the results, anything there? Run the query manually in mysql console, anything there? – Andrew Apr 19 '18 at 17:02
  • are you sure @SystemGlitch . `mysqli_*` is very much alive and safe maybe i didn't get the memo – Rotimi Apr 19 '18 at 17:03
  • @SystemGlitch `mysqli_*` is not deprecated, the deprecated one is `mysql_*` – Julian David Apr 19 '18 at 17:04
  • Indeed, sorry, I deleted my comment. The confusion came from **deprecated aliases** in mysqli as stated [here](http://php.net/manual/en/ref.mysqli.php) – SystemGlitch Apr 19 '18 at 17:06
  • 1
    Maybe the line `require'header.php';` is stopping the script because it is failing, so I want to ask if you have the `error_reporting` enabled in your php.ini to see if it is throwing a warning on that line. – Julian David Apr 19 '18 at 17:17
  • What is in header.php? – gview Apr 19 '18 at 17:19
  • Along with all the other comments, use spaces after require. `require 'file.php'` not `require'file.php'`. Also, why aren't you using AUTO_INCREMENT for your id column? – gview Apr 19 '18 at 17:22
  • This isn't related to your problem but you want your table id to be this: `id` INT UNSIGNED NOT NULL AUTO_INCREMENT – gview Apr 19 '18 at 17:22
  • And while at it, use require_once not require. – gview Apr 19 '18 at 17:25
  • Found it guys. There is something wrong with my header.php file. Also I know this code s prone to SQL Injection attacks. The code is temporary and will only be locally hosted. – Connor Woodford Apr 19 '18 at 17:29

1 Answers1

-1

put this in your database file INSERT INTO products (id, p_name, image, price) VALUES (54, 'sodfgjhpoifunf', 'images/ambient music.jpg', 75.00);

and in your query "SELECT * FROM products"