SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query will not work! Argh!

    This query will not work, I have the connection established dont worry about that.
    PHP Code:
    //See if there is a source where the customer came from.
    if (!empty ($_SERVER['QUERY_STRING']))
    {
        
    $query "SELECT * FROM sources WHERE source = addslashes({$_SERVER['QUERY_STRING']})";
        if (
    $query_result = @mysql_query ($query))
        {
            
    $t mysql_numrows ($query_result);
            if (
    $t != 0)
            {
                while (
    $row = @mysql_fetch_array ($query_result)) {
                    
    $_SESSION['referrer'] = $_SERVER['QUERY_STRING'];
                    echo 
    "Yes!";
                
    $i++;
                }
            }
        }
        else
        {
            echo 
    "Could not run the source query. Please email webmaster <a href=\"mailto:{$config['email']}?subject=Source Query Error On Page {$_SERVER['REQUEST_URI']}\">here</a>.";
            exit;
        }


  2. #2
    SitePoint Evangelist
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $t mysql_numrows ($query_result); 
    Is incorrect, I'm pretty sure. It's it
    PHP Code:
    $t mysql_num_rows ($query_result); 

  3. #3
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might be better of just catching your query string as a variable first. That how I would do it anyway as I could build the query easier. Others may not agree though.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    I don't think addslashes is a sql command, so instead of this:

    PHP Code:
    $query "SELECT * FROM sources WHERE source = addslashes({$_SERVER['QUERY_STRING']})"
    you might try:

    PHP Code:
    $query "SELECT * FROM sources WHERE source = '".addslashes($_SERVER['QUERY_STRING'])."'"


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
  •