Problem with displaying info from a MySQL database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Oberiko
Forum Newbie
Posts: 1
Joined: Mon Apr 05, 2004 1:50 pm

Problem with displaying info from a MySQL database

Post by Oberiko »

Hey all.

I've been working on trying to show information from a MySQL database for quite awhile and decided that I need some help.

Code: Select all

<? echo "<?xml version="1.0" encoding="utf-8"?" . ">\n"; ?>   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <title> Product Catalog </title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  </head> 
<body> 
<h1 align="center"> Product Catalogue </h1> 
<?  
error_reporting(E_ALL); 
// Set up information to access the database 

$host = "****";   
$db_user = "****";  
$db_password = "****";  
$db = $db_user;  

//The connection stuff DOES work.

// Establish a connection to database 

$connection = mysql_connect($host, $db_user, $db_password) or die("Connection Failed: " . mysql_error());  

// Select the database 

   mysql_select_db($db, $connection) or die("Database selection Failed: " . mysql_error());  

// Build SQL statement 

   $sql = "select * from hardware";  

// Run the query 

  $result = mysql_query($sql, $connection) or die("Query Failed: " . mysql_error());  
// Use here document to create table header 
// Make sure there is no space after ENDBLOCK, if you copy paste from my 
// web site an extra space is inserted after ENDBLOCK delete that extra space 
// if you get syntax error on next line 
print <<<ENDBLOCK
   <form action="MyOrder.php" method="post"> 
   <table border="1" width="100%"> 
   <caption> <strong> $sql </strong></caption> 
    <tr> 
      <th width="250"> ID </th> 
      <th> Catagory </th> 
      <th width="100"> Description </th> 
      <th width="25"> Price </th> 
      <th width="25"> Quantity </th> 
      <th width="25"> Image </th> 
    </tr> 
ENDBLOCK; 
// Show database records 
    while ( $row = mysql_fetch_array($result)) {  
       print "<tr>";  
       print "<td>" . $row&#1111;'ID'] . "</td>";  
       print "<td>" . $row&#1111;'Catagory'] . "</td>";  
       print "<td>" . $row&#1111;'Description'] . "</td>";  
       print "<td align='right'>" . $row&#1111;'Price'] . "</td>";  
       print "<td align='right'>" . $row&#1111;'qty'] . "</td>";  
       print "<td align='right'>" . $row&#1111;'image_file'] . "</td>";  
       print "<td align='center'>" . 
               "<input type='checkbox' name='item_selected&#1111;]' value='" . $row&#1111;code] . 
               "' />";
       print "</tr>";  
    }  
print "<tr><td colspan='4' align='right'><input type='submit' value='Order Now' />" . 
        "</td></tr>"; 
print "</table>";  
print "</form>"; 
?>  
</body> 
</html>
When the code's over, I keep getting:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in **** on line 55

The fields in the my table are:
ID - varchar(128)
Catagory - varchar(128)
Description - varchar(128)
Price - decimal(11,2)
qty - int(11)
image_file - varchar(128)

Anyone have any thoughts
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

What is line 55 of the script you gave here?
Post Reply