-2

I'm trying to create a product page from a query result (store ID) that gets sent from a previous page and I need help trouble-shooting the code. I do not get any errors on the results page, but I also do not get any output from the database either when I attempt to echo in the results. Here is my code:

<?php
include 'connect\mbh.php';
$conn = OpenCon();
echo "Connected Successfully";

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

$store = $_GET['STORE_ID'];  
$query = "SELECT * FROM stores WHERE 'STORE_ID' = '$store'";

if ($result = $conn->query($query)) {

    /* fetch object array */
    while ($row = $result->fetch_row()) {
        printf ("%s (%s)\n", $row[0], $row[1]);
    }

    /* free result set */
    $result->close();
}

/* close connection */
$conn->close();
?>

And then later in the text of the site I try to echo in results from the database:

   <img src="images/b_logos/<?php echo $row['LOGO']; ?> 

Any ideas on what I'm doing wrong? I'm clearly a beginner at this! Thanks

mbh
  • 13
  • 3
  • 2
    Get rid of the quotes around `STORE_ID`. – Barmar Jun 27 '19 at 20:01
  • See https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks – Barmar Jun 27 '19 at 20:01
  • You never check for [mysqli errors](http://php.net/manual/en/mysqli.error.php). MySQL errors report differently, and you have to explicitly check for them when your query fails. – aynber Jun 27 '19 at 20:03
  • Thanks Barmar, I removed the quotes but still no results. – mbh Jun 27 '19 at 20:09
  • You would need to build a `$row[]` array and access with `$row[0]['STORE_ID']` or loop `$row`. And won't work with `fetch_row` use https://www.php.net/manual/en/mysqli-result.fetch-assoc.php – AbraCadaver Jun 27 '19 at 20:22
  • @Barmar means the quotes here `FROM stores WHERE 'STORE_ID'` – AbraCadaver Jun 27 '19 at 20:23
  • @AbraCadaver `$row` comes from `while ($row = $result->fetch_row()) {` – Barmar Jun 27 '19 at 20:25
  • @aynber There's no syntax error in the query. It just won't return anything, because `$store` is never the literal string `'STORE_ID'` – Barmar Jun 27 '19 at 20:26
  • @Barmar: Yes so it would be only the last one and `fetch_row` doesn't give an associative array. – AbraCadaver Jun 27 '19 at 20:26
  • Right. Everything that uses `$row` needs to be in that `while` loop. – Barmar Jun 27 '19 at 20:27

1 Answers1

-2

Your image tag is broken.

<img src="images/b_logos/<?php echo $row['LOGO']; ?>">
asiby
  • 3,229
  • 29
  • 32
  • This is true, but it doesn't explain why the `while` loop doesn't print anything. The quoting problem explains that. – Barmar Jun 27 '19 at 20:27