0

I would like to know what exactly is preventing this code from showing item_name, item_weight, item_value,item_description. All of this information gets properly stored into phpadmin. When I go to show the table it shows only the headers of the table and not the content.

<?php

$connection = mysqli_connect("localhost", "*******", "******");

//select database.
mysql_select_db('brandind_dnd');

//gathers all info from 'items' in sql and stores into variable sql.
$sql="SELECT * FROM items";

//inserted stored_items variable into mysql_fetch_assoc() in while loop 
below.
$stored_items = mysql_query($sql);
?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Item</title>
<style>

</style>
</head>
<body>
<div class="additem">
<h1>Add Item</h1>
<form action="insert.php" method="post">
<p>
    <label for="itemName">Name:</label>
    <input type="text" name="item_name" id="itemName">
</p>
<p>
    <label for="itemWeight">Weight:</label>
    <input type="text" name="item_weight" id="itemWeight">
</p>
<p>
    <label for="itemValue">Value:</label>
    <input type="text" name="item_value" id="itemValue">
</p>
<p>
    <label for="itemDesc">Description:</label>
    <input type="text" name="item_desc" id="itemDesc">
</p>
<input type="image" id="inventory" name="submit" src="inventory_image.png" 
border="0" alt="Submit" /></a><br><br>
</div>
<table maxwidth="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th id="table_col_1">Item</th>
<th id="table_col_2">Weight</th>
<th id="table_col_3">Value</th>
<th id="table_col_4">Description</th>

<tr>

<?php 
($item=mysql_fetch_assoc($stored_items)){
echo "<tr>";
echo "<td>".$item['item_name']."</td>";
echo "<td>".$item['item_weight']."</td>";
echo "<td>".$item['item_value']."</td>";
echo "<td>".$item['item_description']."</td>";
echo "</tr>";
}//end while
?>'

</table>
</form>
</body>
</html>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    You're mixing `mysqli_*` and `mysql_*` drivers, they're completely different despite their similar names. Don't use the `mysql_*` functions, they have been deprecated since v5.5 (Jun 2013) and removed since v7.0 (Dec 2015). Instead use the [**mysqli_***](https://secure.php.net/manual/en/book.mysqli.php) or [**PDO**](https://secure.php.net/manual/en/book.pdo.php) functions with [**prepared statements**](https://secure.php.net/manual/en/pdo.prepare.php) and [**bound parameters**](https://secure.php.net/manual/en/pdostatement.bindparam.php). – Alex Howansky Apr 20 '17 at 18:27
  • @AlexHowansky is completely right. In addition to that, I don't see a `while` in your "loop" at the table below, so if that even works it would only show one result. – JensV Apr 20 '17 at 18:29
  • the markup looks invalid, inspect it with developer tools – Gntem Apr 20 '17 at 18:29
  • Okay thanks. the while missing was a typo. – Brandin Dennin Apr 20 '17 at 18:36

0 Answers0