mindapolis Posted October 6, 2011 Share Posted October 6, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/ Share on other sites More sharing options...
Maq Posted October 6, 2011 Share Posted October 6, 2011 You're missing a ; before the terminating brace. Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276556 Share on other sites More sharing options...
mindapolis Posted October 6, 2011 Author Share Posted October 6, 2011 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\5246561\html\treats.php on line 30 Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276569 Share on other sites More sharing options...
Maq Posted October 6, 2011 Share Posted October 6, 2011 $result_set Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276573 Share on other sites More sharing options...
mindapolis Posted October 6, 2011 Author Share Posted October 6, 2011 that goes where` Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276577 Share on other sites More sharing options...
Maq Posted October 6, 2011 Share Posted October 6, 2011 You have: $result_set= mysql_query($query); but then you use: while($row = mysql_fetch_array($result)) Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276584 Share on other sites More sharing options...
mindapolis Posted October 6, 2011 Author Share Posted October 6, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276589 Share on other sites More sharing options...
mindapolis Posted October 7, 2011 Author Share Posted October 7, 2011 can someone please help me with this problem ? Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276631 Share on other sites More sharing options...
ebolt007 Posted October 7, 2011 Share Posted October 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276632 Share on other sites More sharing options...
mindapolis Posted October 7, 2011 Author Share Posted October 7, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276638 Share on other sites More sharing options...
codefossa Posted October 7, 2011 Share Posted October 7, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276651 Share on other sites More sharing options...
mindapolis Posted October 7, 2011 Author Share Posted October 7, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276663 Share on other sites More sharing options...
mikesta707 Posted October 7, 2011 Share Posted October 7, 2011 Well you are selecting everything from your table... Are you sure you have more than two rows? Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276674 Share on other sites More sharing options...
mindapolis Posted October 7, 2011 Author Share Posted October 7, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1276913 Share on other sites More sharing options...
mindapolis Posted October 7, 2011 Author Share Posted October 7, 2011 does anyone know what 's going on? Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277004 Share on other sites More sharing options...
Maq Posted October 7, 2011 Share Posted October 7, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277006 Share on other sites More sharing options...
mindapolis Posted October 7, 2011 Author Share Posted October 7, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277071 Share on other sites More sharing options...
mindapolis Posted October 8, 2011 Author Share Posted October 8, 2011 I figured out the problem. Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277136 Share on other sites More sharing options...
Maq Posted October 9, 2011 Share Posted October 9, 2011 I figured out the problem. Then please mark as solved and share the solution if you want. Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277547 Share on other sites More sharing options...
razormedia Posted October 9, 2011 Share Posted October 9, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1277569 Share on other sites More sharing options...
mindapolis Posted October 12, 2011 Author Share Posted October 12, 2011 that made things worse Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1278567 Share on other sites More sharing options...
mindapolis Posted October 12, 2011 Author Share Posted October 12, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1278598 Share on other sites More sharing options...
Muddy_Funster Posted October 12, 2011 Share Posted October 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1278609 Share on other sites More sharing options...
mindapolis Posted October 12, 2011 Author Share Posted October 12, 2011 that helped but how do I make it display like the attached diagram shows [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1278625 Share on other sites More sharing options...
mindapolis Posted October 12, 2011 Author Share Posted October 12, 2011 I know how to arrange things in the table cell. it 's the displaying different products in a second column that I'm struggling with. Quote Link to comment https://forums.phpfreaks.com/topic/248573-unexpected/#findComment-1278633 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.