Jump to content

Recommended Posts

Hi, could someone please tell me why I'm getting an unexpected { error in the following code.  I have went over it several times and everything seems to be matching. 

 

<?php
require_once("functions.php"); 
?>  
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
DatabaseConnection();  

$query= "SELECT * FROM treats";
$result_set= mysql_query($query);
/*if( $result_set = mysql_query($query) ) {

while( $products = mysql_fetch_row($result_set) ) {
     echo $products[0];
     echo $products[1]; 
     echo $products[2];
     echo $products[3]; 
     echo $products[4];  
     echo "<img src=\"{$products[5]}\">"; // assuming this is where the image url is
     }
}
//print_r(mysql_fetch_row($result_set));*/
$output = "<table>";
while($row = mysql_fetch_array($result)) 
{
$productDetail1['product_id']; 
$productDetail2['product_title']; 
$productDetail3['product_Description']; 
$productDetail4['price']; 
$productDetail5['product_pic'];  
$output .= (" 
	<tr>
		<td>".$productDetail1['product_id'] ."</td>  
	</tr>
	") 
}
$output .= "</table>";
?>   
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/
Share on other sites

Isn't that what I have ?

 

<?php
require_once("functions.php"); 
?>  
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
DatabaseConnection();  

$query= "SELECT * FROM treats";
$result_set= mysql_query($query);

$output = "<table>";
while($row = mysql_fetch_array($result)) 
{
$productDetail1['product_id']; 
$productDetail2['product_title']; 
$productDetail3['product_Description']; 
$productDetail4['price']; 
$productDetail5['product_pic'];  
$output .= (" 
	<tr>
		<td>".$productDetail1['product_id'] ."</td>  
	</tr>
	") 
;}
$output .= "</table>";
echo $output;
?>   
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276589
Share on other sites

He means you have to change

$query= "SELECT * FROM treats";
$result_set= mysql_query($query);

$output = "<table>";
while($row = mysql_fetch_array($result)) 
{

to

$query= "SELECT * FROM treats";
$result_set= mysql_query($query);

$output = "<table>";
while($row = mysql_fetch_array($result_set)) 
{

 

$result_set has to be the mysql_fetch_array since that's what your querying.

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276632
Share on other sites

now it 's displaying a blank page

 

<?php
require_once("functions.php"); 
?>  
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
DatabaseConnection();  

$query= "SELECT * FROM treats";
$result_set= mysql_query($query) or die(mysql_error());

$output = "<table>";
while($row = mysql_fetch_array($result_set)) 
{
$productDetail1['product_id']; 
$productDetail2['product_title']; 
$productDetail3['product_Description']; 
$productDetail4['price']; 
$productDetail5['product_pic'];  
$output .= (" 
	<tr>
		<td>".$productDetail1['product_id'] ."</td>  
	</tr>
	") 
;}
$output .= "</table>";
echo $output;
/*while($row = mysql_fetch_array($result)) 
 {
    echo "<table>";	 
   	    echo "</td><td>";
	echo $row['product_id'];
	echo "</td><td>";
	echo $row['product_title'];
	echo "</td><td>";  
	echo "</rd></tr>";
 }
    echo "</table>";
*/
?>   
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276638
Share on other sites

I think this is what you're trying to accomplish?

 

<?php require_once("functions.php"); ?>  

<!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>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
    </head>

    <body>
        <?php
        
        DatabaseConnection();

        $query = "SELECT * FROM treats";
        $result_set = mysql_query($query) or die(mysql_error());

        $output = "<table>";
        while ($row = mysql_fetch_array($result_set))
        {
            $output .= (" 
	<tr>
		<td>" . $row['product_id'] . "</td>  
	</tr>
	");
        }
        $output .= "</table>";
        echo $output;
        /* while($row = mysql_fetch_array($result)) 
          {
          echo "<table>";
          echo "</td><td>";
          echo $row['product_id'];
          echo "</td><td>";
          echo $row['product_title'];
          echo "</td><td>";
          echo "</rd></tr>";
          }
          echo "</table>";
         */

        ?>   
    </body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276651
Share on other sites

ok, that helped some but, now it 's only displaying the first two rows. 

 

<?php
require_once("functions.php"); 
?>  
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
DatabaseConnection();  

$query= "SELECT * FROM treats";
$result_set= mysql_query($query) or die(mysql_error());

$output = "<table>";
while($row = mysql_fetch_array($result_set)) 
{
/*$productDetail1['product_id']; 
$productDetail2['product_title']; 
$productDetail3['product_Description']; 
$productDetail4['price']; 
$productDetail5['product_pic'];  */
$output .= (" 
	<tr>
		<td>".$row['product_id']."</td>  
		<td>".$row['product_title']."</td>
		<td>".$row['product_Description']."</td>
		<td>".$row['product_price']."</td>			
	</tr>
	") 
;}
$output .= "</table>";
echo $output;
/*while($row = mysql_fetch_array($result)) 
 {
    echo "<table>";	 
   	    echo "</td><td>";
	echo $row['product_id'];
	echo "</td><td>";
	echo $row['product_title'];
	echo "</td><td>";  
	echo "</rd></tr>";
 }
    echo "</table>";
*/
?>   
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276663
Share on other sites

now it 's not displaying anything

 

<?php
require_once("functions.php"); 
?>  
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
DatabaseConnection();  

$query= "SELECT * FROM treats";
$result_set= mysql_query($query) or die(mysql_error());

$output = "<table>";
while($row = mysql_fetch_array($result_set)) 
$product_id = $row['product_id'];
$product_title = $row['product_title'];
$product_Description = $row['product_Description'];
$product_price = $row['product_price'];
{
/*$productDetail1['product_id']; 
$productDetail2['product_title']; 
$productDetail3['product_Description']; 
$productDetail4['price']; 
$productDetail5['product_pic'];  */
$output .= (" 
	<tr>
		<td>".$row['product_id']."</td>  
		<td>".$row['product_title']."</td>
		<td>".$row['product_Description']."</td>
		<td>".$row['product_price']."</td>			
	</tr>
	") 
;}
$output .= "</table>";
echo $output;
/*while($row = mysql_fetch_array($result)) 
 {
    echo "<table>";	 
   	    echo "</td><td>";
	echo $row['product_id'];
	echo "</td><td>";
	echo $row['product_title'];
	echo "</td><td>";  
	echo "</rd></tr>";
 }
    echo "</table>";
*/
?>   
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276913
Share on other sites

Put these two lines directly after your opening PHP tag:

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

If you're not receiving nor SQL or PHP errors than double check that your query actually returns results.

Are you sure your DatabaseConnection() method is connecting?

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277006
Share on other sites

its still not displaying anything

 

<?php
require_once("functions.php"); 
?>  
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
ini_set ("display_errors", "1");
error_reporting(E_ALL);
DatabaseConnection();  

$query= "SELECT * FROM treats";
$result_set= mysql_query($query) or die(mysql_error());

$output = "<table>";
while($row = mysql_fetch_array($result_set)) 
$product_id = $row['product_id'];
$product_title = $row['product_title'];
$product_Description = $row['product_Description'];
$product_price = $row['product_price'];
{
/*$productDetail1['product_id']; 
$productDetail2['product_title']; 
$productDetail3['product_Description']; 
$productDetail4['price']; 
$productDetail5['product_pic'];  */
$output .= (" 
	<tr>
		<td>".$row['product_id']."</td>  
		<td>".$row['product_title']."</td>
		<td>".$row['product_Description']."</td>
		<td>".$row['product_price']."</td>			
	</tr>
	");
}
$output .= "</table>";
echo $output;
/*while($row = mysql_fetch_array($result)) 
 {
    echo "<table>";	 
   	    echo "</td><td>";
	echo $row['product_id'];
	echo "</td><td>";
	echo $row['product_title'];
	echo "</td><td>";  
	echo "</rd></tr>";
 }
    echo "</table>";
*/
?>   
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277071
Share on other sites

change the section from this:

 

<tr>
		<td>".$row['product_id']."</td>  
		<td>".$row['product_title']."</td>
		<td>".$row['product_Description']."</td>
		<td>".$row['product_price']."</td>			
	</tr>

 

to this

<tr>
		<td>".$product_id."</td>  
		<td>".$product_title."</td>
		<td>".$product_Description."</td>
		<td>".$product_price."</td>			
	</tr>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277569
Share on other sites

with the suggested code the following page displays. 

 

http://auntievics.com/treats.php

 

<?php
require_once("functions.php"); 
?>  
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
td {
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #30C;
border-right-color: #30C;
border-bottom-color: #30C;
border-left-color: #30C;
}
</style>
</head>

<body>
<?php
navBar();
echo "<form action=\"\" method=\"post\" name=\"catalog\">";
  
DatabaseConnection();  

  $query = "SELECT * FROM treats"; 
        $result_set = mysql_query($query) or die(mysql_error());
$i = 0;
        $output = "<table>";
        while ($row = mysql_fetch_array($result_set))
        {
            $output .= (" 
			<tr>
				<td>".$product_id."</td>  
		<td>".$product_title."</td>
		<td>".$product_Description."</td>
		<td>".$product_price."</td>					
			</tr>
	");
        }
        $output .= "</table>";
        echo $output;
?>   
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1278598
Share on other sites

You do not have a value for the variables $product_id, $product_title, $product_description or $product_price! razormedia is eather trying to mess with you or seriously not qualified to be posting help on this thread.

 

copy/paste this and see what you get:

<?php
require_once("functions.php"); 
?>  
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
td {
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #30C;
border-right-color: #30C;
border-bottom-color: #30C;
border-left-color: #30C;
}
</style>
</head>

<body>
<?php
navBar();
echo "<form action=\"\" method=\"post\" name=\"catalog\">";
  
DatabaseConnection();  

  $query = "SELECT * FROM treats"; 
        $result_set = mysql_query($query) or die(mysql_error());
$i = 0;
        echo = "<table>";
        while ($row = mysql_fetch_array($result_set))
        {
            echo"<tr><td>{$row['product_id']}</td><td>{$row['product_title']}</td><td>{$row['product_Description']}</td><td>{$row['product_price']}</td></tr>";
        }
        echo "</table>";
?>   
</form>
</body>
</html>

 

also make sure that that random upper case D in product_description is actualy ment to be upper case, or else it's going to be a problem.

Link to comment
https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1278609
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.