SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET not working

    For some reason my script does not seem to recognize any value of $_GET['a']

    PHP Code:
    if($page=="articles") {
        
    $aid = (int)$_GET['a'];
        if(
    $aid) {
            
    $Query "SELECT title, body FROM articles WHERE id = $aid";
            
    $Result mysql_query($Query)
                or die(
    "Could not select article: " mysql_error());
            
    $Row mysql_fetch_array($Result);
            echo
                
    '
            <h3>'
    .stripslashes($Row[title]).'</h3>
            <p class="full_text">'
    .nl2br(stripslashes($Row[body])).'</p>
                '
    ;
        } else {
            
    $Query "SELECT id, title FROM articles ORDER BY title";
            
    $Result mysql_query($Query)
                or die(
    "Could not select articles: " mysql_error());
            echo 
    '<ul>';
            while(
    $Row mysql_fetch_array($Result)) {
                
    $title stripslashes($Row['title']);
                
    $id $Row['id'];
                echo
                    
    '
                <li><a href="/articles?a='
    .$id.'"><strong>'.$title.'</strong></a></li>
                    '
    ;
            }
            echo 
    '</ul>';
        }

    It always goes to the else statement, listing all the articles.

    Try it out at http://westernmortgagecompany.com/articles

    Any help much appreciated!
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  2. #2
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps try:

    PHP Code:
    if($page=="articles") {
        if(isset(
    $_GET['a']) {
            
    $aid=(int) $_GET['a'];
            
    $Query "SELECT title, body FROM articles WHERE id = $aid";
            
    $Result mysql_query($Query)
                or die(
    "Could not select article: " mysql_error());
            
    $Row mysql_fetch_array($Result);
            echo
                
    '
            <h3>'
    .stripslashes($Row[title]).'</h3>
            <p class="full_text">'
    .nl2br(stripslashes($Row[body])).'</p>
                '
    ;
        } else {
            
    $Query "SELECT id, title FROM articles ORDER BY title";
            
    $Result mysql_query($Query)
                or die(
    "Could not select articles: " mysql_error());
            echo 
    '<ul>';
            while(
    $Row mysql_fetch_array($Result)) {
                
    $title stripslashes($Row['title']);
                
    $id $Row['id'];
                echo
                    
    '
                <li><a href="/articles?a='
    .$id.'"><strong>'.$title.'</strong></a></li>
                    '
    ;
            }
            echo 
    '</ul>';
        }


  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, how are you getting the value of $page? Not sure how you are translasting your URL, but your rewrite rule might not be working properly or something like that, so that $_GET['a'] is not even getting set. Try using print_r to see what is in $_GET array

  4. #4
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Young Twig: Nope, not working

    wise: the code was just a snippet from the full page. The rewrite rule is:

    RewriteEngine On
    RewriteRule ^([A-Za-z\-]+)/?$ index.php?page=$1 [L]
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  5. #5
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well could be missing something but you want to access $_GET['page'] according to your rewrite, not $_GET['a']

    Edit: Looking at the page I think you need to add &a=2 instead of ?a=2

    Silly

  6. #6
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I get it. You're trying to access index.php?page=articles&a=2 You need to add the "Query String Append" flag to your RewriteRule.

    Code:
    RewriteEngine On
    RewriteRule ^([A-Za-z\-]+)/?$ index.php?page=$1 [L,QSA]

  7. #7
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, thankyou
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches


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
  •