www.webdeveloper.com
Results 1 to 6 of 6

Thread: php mysql help

  1. #1
    Join Date
    Nov 2007
    Posts
    22

    php mysql help

    How can i make this work?

    in the top of my php file i have
    PHP Code:
    $stuff $_GET['p'];
    $stuff end(explode('='$_SERVER['REQUEST_URI'])); 
    further down i have
    PHP Code:
    $sql 'SELECT * FROM `quotes` where game = \'$stuff\' LIMIT 0, 30 '
    Fatal error: Database::_sql(); -> Query error:

    why wont this work? :/
    Last edited by evania; 08-14-2010 at 10:31 AM.

  2. #2
    Join Date
    Mar 2007
    Posts
    946
    Is that the exact database error?

    Also, what is stored in the $stuff variable?

    Plus I also don't understand why you set the $stuff variable on the first line then on the next line you overwrite it.

  3. #3
    Join Date
    Nov 2007
    Posts
    22
    ah sorry, in $stuff everyting after the "=" in this url is stored http://mypage.net/index.php?p=twarp so for that url "twarp" would be in $stuff

    and yes that's the exact error im getting

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    You have the query string in single quotes, and therefore $stuff will not be evaluated as a PHP variable.
    PHP Code:
    $sql "SELECT * FROM `quotes` where game = '$stuff' LIMIT 0, 30"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Nov 2007
    Posts
    22
    Quote Originally Posted by NogDog View Post
    You have the query string in single quotes, and therefore $stuff will not be evaluated as a PHP variable.
    PHP Code:
    $sql "SELECT * FROM `quotes` where game = '$stuff' LIMIT 0, 30"
    thank you, however i noticed this was just 1 part of my problem

    this is my code

    PHP Code:
    $stuff $_GET['p'];
    $stuff end(explode('='$_SERVER['REQUEST_URI']));
    case 
    '$stuff':
                    
    $sql "SELECT * FROM `quotes` where game = '$stuff' LIMIT 0, 30";
                    
    $r $db->_sql($sql);
                    while (
    $row $db->fetch_row($r)) {
                        
    $tpl->set('q_id'$row['id']);
                        
    $tpl->set('q_rating'$row['rating']);
                        
    $tpl->set('quote'$row['quote']);
                        
    $sql "SELECT ip FROM ".$_qdbs[tpfx]."votes WHERE id='".mysql_real_escape_string($row['id'])."' AND ip='".mysql_real_escape_string($ip)."'";
                        
    $r2 $db->_sql($sql);
                        
    $row2 $db->fetch_row($r2);
                        if (
    $row2['ip'] != $ip) {
                            
    $rate $tpl->fetch($tpl->tdir.'quote_rate.tpl');
                            
    $tpl->set('q_rate'$rate);
                        } else {
                            
    $tpl->set('q_rate''');
                        }
                        print(
    $tpl->fetch($tpl->tdir.'game.tpl'));
                    } 
    the "case '$stuff':" at the top wont work either :/ the case part is so that if my url is http://mypage.net/index.php?p=twarp the code under "case 'someting':" only runt if it matches whats after the = and currently having $stuff wont work, do you know why? :/

  6. #6
    Join Date
    Mar 2007
    Posts
    946
    First off you are overwritten the first $stuff with the second line
    PHP Code:
    $stuff $_GET['p']; 
    $stuff end(explode('='$_SERVER['REQUEST_URI'])); 
    If this is your whole code then you are missing the start of the switch statement, plus you have $stuff in single quotes for your case statement, which isn't correct because it evaluates $stuff as $stuff and not what is contained in stuff.

    PHP Code:
    case '$stuff'
    //should be
    case $stuff

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles