简体   繁体   中英

php not displaying results on database

I have a database with 4 tables. (products,purchase,customer,user). When I tried to display all rows in products , no results. But in the user table, it displays. What should be the problem? Is it on my database?tables?php code?

Here's my code:

<?php

$db = mysqli_connect("localhost","root","", "prodpurchase");
if (!$db) {
die('Could not connect: ' . mysqli_error());
}

$sql = mysqli_query($db, "select * from user");
if( $sql === FALSE ) {
  die('Query failed returning error: '. mysqli_error());
} else {
   while($row=mysqli_fetch_array($sql))
   {
    echo $row['username']. "<br>";
   }
}
?>

Hope you could help me.

您的代码中有库存,但在您的问题中,您将表产品命名为,这是否很简单?

你检查了表格列中的大写和小写字母了吗?

echo $row['item']. "<br>";

What is 'item'? Shouldn't you be selecting them by $row[0] or $row['products'].. or one of your other columns.

check your variables, for your example, try renaming your vairable $sql to something else, because you might have a similar variable somewhere in your code that you did not show.

try this :

<?php

$db = mysqli_connect("localhost","root","", "prodpurchase");
if (!$db) {
die('Could not connect: ' . mysqli_error());
}

$sqlstackoverflow = mysqli_query($db, "select * from user");
if($sqlstackoverflow === FALSE ) {
  die('Query failed returning error: '. mysqli_error());
} else {
   while($row=mysqli_fetch_array($sqlstackoverflow))
   {
    echo $row['username']. "<br>";
   }
}
?>

Your code references an inventory table but you said your database has a products table (and no inventory table). Because of this, the query is failing.

Just Try With The Following :

<?php
$db = mysqli_connect("localhost","root","","prodpurchase");
if (!$db) {
die('Could not connect: ' . mysqli_error());
}
$sql = mysqli_query($db,"select * from user");
if( $sql === FALSE ) {
  die('Query failed returning error: '. mysqli_error());
} else {
   while($row=mysqli_fetch_array($sql,MYSQLI_ASSOC))
   {    
    echo $row['username']."<br>";    
   }
}
?>

I think this may help you to resolve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM