user3482470 user3482470 - 1 year ago 63
PHP Question

display quantity field in table in php

I'm trying to get my table to look like this

but when I use my code looks like this

I can't get the quantity field or add field to work for the life of me; the quantity field is just blank. I would greatly appreciate some help because I can't get it to work.

<?php require_once("include/db_connect.php"); ?>
<head><title>Displaying Image files using PHP</title></head>
<h1>Displaying Images from an Image table using PHP</h1>


$db_link = db_connect("project");

// Retrieve table properties

$fields = mysql_list_fields("project", "bookstore");
$num_columns = mysql_num_fields($fields);

// Make a simple database query to select all columns and rows

$query = "SELECT * FROM bookstore";
$result = mysql_query($query) or die("SQL query failed");

// Display results as an HTML table. Note how mysql_field name
// uses the $fields object to extract the column names

echo '<table border="1" cellpadding = "5" >';

// Display the column names

echo "<tr>";
for ($i = 0; $i < $num_columns; $i++)
echo "<th>", mysql_field_name($fields, $i), "</th>";

echo "<th>"Quantity "</th>";

echo "</tr>";

// Loop over the rows of the table.
// $row contains the information for each row
// Refer to the names of the fields in the table
// Must ahow the path where the image files are held

while ($row = mysql_fetch_assoc($result))
echo "<tr>
<form action='somethingToHandleForm.php' method='post'>";

echo "<td>". $row['isbn']. "</td>";
echo "<td>". $row['title']."</td>";
echo "<td>". $row['author']."</td>";
echo "<td>". $row['pub']."</td>";
echo "<td>". $row['year']."</td>";
echo "<td>". $row['price']."</td>";
echo "<td><input type='text' name='quantity' value=".$row['quantity']."/></td>";
echo "<td><input type='submit' value='add></td>";
echo "</form>";

echo "</tr>";

echo "</table>";

// Free the resources and close the connection


Answer Source

One thing I noticed is you're missing a single quote in this line after value=add:

<input type='submit' value='add>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download