slimline77
06-03-2010, 11:59 AM
Hi all,
Almost finished my site but there's one problem I can't solve. I used a tutorial called Plaincart (phpwebcomerce.com) to build a shopping cart and I put in a product search box so users can search for a product in the catalogue. The search outputs basic info of the product and I want to output a link to the product in the catalogue so user can get more details. This is where I'm having the problem.
$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];
$catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0;
$pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0;
require_once 'include/header.php';
?>
<?php
$db = mysql_connect('localhost', 'root', '') or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db('dvdff2', $db) or die(mysql_error($db));
?>
<?php
$search = (isset($_GET['search'])) ? $_GET['search'] : '';
$sql = 'SELECT
pd_id
FROM
tbl_product
WHERE
MATCH (pd_name, pd_dir, pd_cast) AGAINST ("' .
mysql_real_escape_string($search, $db) . '" IN BOOLEAN MODE)
ORDER BY
MATCH (pd_name, pd_dir, pd_cast) AGAINST ("' .
mysql_real_escape_string($search, $db) . '" IN BOOLEAN MODE) DESC';
$result = mysql_query($sql, $db) or die(mysql_error($db));
if (mysql_num_rows($result) == 0) {
// echo '<p><strong>No movies found that match the search terms.</strong></p>';//
//I had to leave this out for search as every button that was clicked caused it to come up
} else {
while ($row = mysql_fetch_array($result)) {
output_movie($db, $row['pd_id'], TRUE);
}
}
mysql_free_result($result);
?>
<?php
function output_movie($db, $pd_id, $preview_only = FALSE) {
if (empty($pd_id)) {
return;
}
$sql = 'SELECT
pd_id, pd_name, pd_year, pd_dir, pd_cast, pd_class, pd_price
FROM
tbl_product
WHERE
pd_id = ' . $pd_id;
$result = mysql_query($sql, $db) or die(mysql_error($db));
if ($row = mysql_fetch_assoc($result)) {
extract($row);
echo '<h3 class="blue">' . htmlspecialchars($pd_name) . '</h2>';
echo '<p><b>Release Year:</b> ' . htmlspecialchars($pd_year) . '</p>';
echo '<p><b>Starring:</b> ' . htmlspecialchars($pd_cast) . '</p>';
echo '<p><b>Director:</b> ' . htmlspecialchars($pd_dir) . '</p>';
echo '<p><b>Classification:</b> ' . htmlspecialchars($pd_class) . '</p>';
echo '<p><b>Price: </b> ' . htmlspecialchars($pd_price) . '</p>';
echo 'View More <a href="index.php?c=$catId&p=$pd_id">' . htmlspecialchars($row['pd_name']) . '</a>';
}
mysql_free_result($result);
}
?>
The last bit of code is what's causing the problem. I get the error
Unknown column '$pd_id' in 'where clause'
I don't understand this as $pd_id is not a column but a variable in my code.
I saw in the code there was instances of $pd_id and $pdId but I changed that and it didn't fix the problem. I know the link code is wrong but I'm not sure how to solve this. I know it's hard as Plaincart is probably unfamiliar to most of you but if anybody has any ideas I would be very grateful for your help.
Kind Regards.
Almost finished my site but there's one problem I can't solve. I used a tutorial called Plaincart (phpwebcomerce.com) to build a shopping cart and I put in a product search box so users can search for a product in the catalogue. The search outputs basic info of the product and I want to output a link to the product in the catalogue so user can get more details. This is where I'm having the problem.
$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];
$catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0;
$pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0;
require_once 'include/header.php';
?>
<?php
$db = mysql_connect('localhost', 'root', '') or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db('dvdff2', $db) or die(mysql_error($db));
?>
<?php
$search = (isset($_GET['search'])) ? $_GET['search'] : '';
$sql = 'SELECT
pd_id
FROM
tbl_product
WHERE
MATCH (pd_name, pd_dir, pd_cast) AGAINST ("' .
mysql_real_escape_string($search, $db) . '" IN BOOLEAN MODE)
ORDER BY
MATCH (pd_name, pd_dir, pd_cast) AGAINST ("' .
mysql_real_escape_string($search, $db) . '" IN BOOLEAN MODE) DESC';
$result = mysql_query($sql, $db) or die(mysql_error($db));
if (mysql_num_rows($result) == 0) {
// echo '<p><strong>No movies found that match the search terms.</strong></p>';//
//I had to leave this out for search as every button that was clicked caused it to come up
} else {
while ($row = mysql_fetch_array($result)) {
output_movie($db, $row['pd_id'], TRUE);
}
}
mysql_free_result($result);
?>
<?php
function output_movie($db, $pd_id, $preview_only = FALSE) {
if (empty($pd_id)) {
return;
}
$sql = 'SELECT
pd_id, pd_name, pd_year, pd_dir, pd_cast, pd_class, pd_price
FROM
tbl_product
WHERE
pd_id = ' . $pd_id;
$result = mysql_query($sql, $db) or die(mysql_error($db));
if ($row = mysql_fetch_assoc($result)) {
extract($row);
echo '<h3 class="blue">' . htmlspecialchars($pd_name) . '</h2>';
echo '<p><b>Release Year:</b> ' . htmlspecialchars($pd_year) . '</p>';
echo '<p><b>Starring:</b> ' . htmlspecialchars($pd_cast) . '</p>';
echo '<p><b>Director:</b> ' . htmlspecialchars($pd_dir) . '</p>';
echo '<p><b>Classification:</b> ' . htmlspecialchars($pd_class) . '</p>';
echo '<p><b>Price: </b> ' . htmlspecialchars($pd_price) . '</p>';
echo 'View More <a href="index.php?c=$catId&p=$pd_id">' . htmlspecialchars($row['pd_name']) . '</a>';
}
mysql_free_result($result);
}
?>
The last bit of code is what's causing the problem. I get the error
Unknown column '$pd_id' in 'where clause'
I don't understand this as $pd_id is not a column but a variable in my code.
I saw in the code there was instances of $pd_id and $pdId but I changed that and it didn't fix the problem. I know the link code is wrong but I'm not sure how to solve this. I know it's hard as Plaincart is probably unfamiliar to most of you but if anybody has any ideas I would be very grateful for your help.
Kind Regards.