PHP code error in Xampp 1.8.1 but ok in Xampplite 1.7.3

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP code error in Xampp 1.8.1 but ok in Xampplite 1.7.3

Postby angusmwm » 07. October 2012 17:58

I'm new and learning the php & MySQL now. When I tried to run the php code as the following in FireFox, there is error under the Xampp 1.8.1 but no any problem in Xampplite 1.7.3. Note, I'm using the Netbeans 7.2 as my IDE. The code is:

<?php
require 'database.php';

// Get category ID
$category_id = $_GET['category_id'];
if (!isset($category_id)) {
$category_id = 1;
}

// Get name for current category
$query = "SELECT * FROM categories
WHERE categoryID = $category_id";
$category = $db->query($query);
$category = $category->fetch();
$category_name = $category['categoryName'];

// Get all categories
$query = 'SELECT * FROM categories
ORDER BY categoryID';
$categories = $db->query($query);

// Get products for selected category
$query = "SELECT * FROM products
WHERE categoryID = $category_id
ORDER BY productID";
$products = $db->query($query);
?>
<!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">
<!-- the head section -->
<head>
<title>My Guitar Shop</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>

<!-- the body section -->
<body>
<div id="page">
<div id="main">

<h1>Product List</h1>

<div id="sidebar">
<!-- display a list of categories -->
<h2>Categories</h2>
<ul class="nav">
<?php foreach ($categories as $category) : ?>
<li>
<a href="?category_id=<?php echo $category['categoryID']; ?>">
<?php echo $category['categoryName']; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>

<div id="content">
<!-- display a table of products -->
<h2><?php echo $category_name; ?></h2>
<table>
<tr>
<th>Code</th>
<th>Name</th>
<th class="right">Price</th>
</tr>
<?php foreach ($products as $product) : ?>
<tr>
<td><?php echo $product['productCode']; ?></td>
<td><?php echo $product['productName']; ?></td>
<td class="right"><?php echo $product['listPrice']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div><!-- end main -->
<div id="footer"></div>
</div><!-- end page -->
</body>
</html>

The code is coming out from one of the php & MySQL books, Murach's.....I even tried to run it under the linux(ubuntu) , but same error as the full version of Xampp 1.8.1 in Windows. I really can't figure out what's the problem. Can someone help? Thanks so much.
angusmwm
 
Posts: 1
Joined: 07. October 2012 17:46
XAMPP Version: 5.6.3
Operating System: Windows XP

Re: PHP code error in Xampp 1.8.1 but ok in Xampplite 1.7.3

Postby JJ_Tagy » 07. October 2012 18:09

What is the error?
JJ_Tagy
 
Posts: 536
Joined: 30. January 2012 13:44
XAMPP Version: 1.8.3
Operating System: Windows 7 x64

Re: PHP code error in Xampp 1.8.1 but ok in Xampplite 1.7.3

Postby WilliL » 08. October 2012 20:15

usualy a foreach loop is written
Code: Select all
<?PHP
foreach ( $var as $value )
{
  echo 'Wert: ' . $value . '<br>' . "\n";
}
?>


your code
Code: Select all
<?php foreach ($products as $product) : ?>
   <tr>
         <td><?php echo $product['productCode']; ?></td>
          ...
   </tr>
<?php endforeach; ?>


I don't know "Netbeans 7.2". If it's an code interpreter, mybe it doesn't fit with the php version (just a guess)
Willi
WilliL
 
Posts: 621
Joined: 08. January 2010 10:54
XAMPP Version: 5.5.19
Operating System: Win7Home Prem 64 SP1

Re: PHP code error in Xampp 1.8.1 but ok in Xampplite 1.7.3

Postby Altrea » 09. October 2012 03:57

WilliL wrote:usualy a foreach loop is written
Code: Select all
<?PHP
foreach ( $var as $value )
{
  echo 'Wert: ' . $value . '<br>' . "\n";
}
?>


your code
Code: Select all
<?php foreach ($products as $product) : ?>
   <tr>
         <td><?php echo $product['productCode']; ?></td>
          ...
   </tr>
<?php endforeach; ?>

The foreach loop seems to be okay in my opinion.

WilliL wrote:I don't know "Netbeans 7.2". If it's an code interpreter, mybe it doesn't fit with the php version (just a guess)

Netbeans was designed to be a very good Java IDE and is now able to work with other languages like php too. In the configuration you can (as with many other IDEs) point to the place of the php.exe for debugging purposes, but without knowing then exact error message that is a shot into the blue.

Maybe it's something basic like "Notice: undefinded index category_id in ...", but only the original poster knows.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6583
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 45 guests