Results 1 to 4 of 4

Thread: Plaincart Search Box/ Output Product Link

  1. #1
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Plaincart Search Box/ Output Product Link

    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.
    PHP Code:
    $_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>';
    PHP Code:
    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.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Whats the out put if you echo $sql in the fuction?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Bluewalrus,
    Sorry I don't think I explained properly, the search function works as in I get the product details displayed including a link to product detail. However when I click the link I get the error
    Unknown column '$pd_id' in 'where clause'
    so the link address is obviously wrong. The c=$catId&p=$pd_id is wrong but I don't know why?
    I tried to echo $sql but I'm not sure exactly how to as it just echoed the word $sql. I'm not very good at php.
    Thanks for replying, sorry I took so long to answer as I'm working really hard to try and finish.

  4. #4
    Join Date
    Jun 2010
    Location
    South Australia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi slimline 77,
    I have used plaincart before and have a fair understanding of how it works.

    Have a look at the code here:

    else {
    while ($row = mysql_fetch_array($result)) {
    output_movie($db, $row['pd_id'], TRUE);
    }



    I think the variable $pd_id now has to be set at this point like so

    else {
    while ($row = mysql_fetch_array($result)) {
    $pd_id=$row['pd_id'];
    output_movie($db, $pd_id, TRUE);
    }

    That may be the answer to the problem.

    Also, I may be mistaken here but looking at the link:
    echo 'View More <a href="index.php?c=$catId&p=$pd_id">' . htmlspecialchars($row['pd_name']) . '</a>';

    Should this be returning to the 'store.php' page and not the index.php page, therefore this line should be:

    echo 'View More <a href="store.php?c=$catId&p=$pd_id">' . htmlspecialchars($row['pd_name']) . '</a>';

    I hope this helps
    Last edited by rickybacker60; 06-06-2010 at 01:01 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •