SELECT statement trouble in PHP

Posted on 2006-06-05
Last Modified: 2010-04-17
I have a query:
$displ_query  = "SELECT * FROM content_ WHERE content_id = $_SERVER['HTTP_REFERER']";

The idea is to trap the sent url:
echo "<u><a href='_cont/_main.php?sender=displ_body_qry&content_id=$content_id'";

where the $content_id variable from the calling page is equal to a content id within my database.

I just don't know how this can be done. Please help if you can.
Question by:rae_rae
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    please try this:
    $displ_query  = "SELECT * FROM content_ WHERE content_id = '{$_SERVER['HTTP_REFERER']}'";
    LVL 3

    Author Comment

    Thanks but no dice. The {$_SERVER['HTTP_REFERER']} echos out as:

    I need it to only contain:
    $content_id, which from above you can see is in
    echo "<u><a href='_cont/_main.php?sender=displ_body_qry&content_id=$content_id'";
    LVL 142

    Accepted Solution

    what about this:
    $displ_query  = "SELECT * FROM content_ WHERE content_id = '{$_GET['content_id']}'";
    LVL 3

    Author Comment

    $displ_query  = "SELECT * FROM content_ WHERE section_name='{$_GET['section_name']}";

    echos out the right variable.
    LVL 5

    Expert Comment

    Two things:

    1. You don't need to place quotes around array indexes within strings.
    2. You need to put quotes around string values in queries.

    Try this:

    $displ_query  = "SELECT * FROM content_ WHERE content_id = '$_SERVER[HTTP_REFERER]' ";

    Alternatively you could use the . operater for concatenation:

    $displ_query  = "SELECT * FROM content_ WHERE content_id = '" . $_SERVER['HTTP_REFERER'] . "'";

    Hope this helps.
    LVL 3

    Author Comment

    Thanks a ton!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    improve Shell script 5 117
    bigDiff challenge 17 58
    fizzArray3  challenge 1 47
    java constructor error 8 65
    A short article about a problem I had getting the GPS LocationListener working.
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now