Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    I have this code
    PHP Code:
    <?php
    $result 
    mysql_query("SELECT * FROM wplanet_click_counter WHERE id='$id");
    $row mysql_fetch_array($result);
        
    $id=$row['id'];
        
    $count=$row['count'];
        
    $count $count 1;
        
        
    $update "UPDATE wplanet_click_counter SET count='$count' WHERE id='$id' ";
        
    $updatesql mysql_query($update);
            
    $sql mysql_query("SELECT url FROM wplanet_click_counter WHERE id='$id'");
    $row mysql_fetch_array($result);
    $url $row['url'];
    echo 
    "<script language=\"JavaScript\">document.location.href=\""$url ."\"</script>";
    mysql_close();
    ?>
    That code SHOULD add +1 to the count column when a user was redirected to http://www.urlofthescript.com/script?id=1 (where id, custom Id of the site redirected.)But it doesnt redirect and doesn't add +1 in count. What's wrong about it ???
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    1. Never, ever do SELECT *. Instead SELECT only what you need.
    2. The SELECT is redundant. Just use:
    Code:
    UPDATE wplanet_click_counter SET count = count + 1 WHERE id = $id;
    3. For redirects, this is often the best choice:
    Code:
    header("Location: $url");
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Just a note on the header("") function in PHP... it actually writes to the HTTP Header information sent with the page, which MUST be written before ANYTHING is written to the document. So if you're going to use it, make sure there's no HTML before it.

  5. #4
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    What's wrong this SELECT * fillburt1?
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  6. #5
    Junior Member
    Join Date
    May 2003
    Location
    New York
    Posts
    8
    Member #
    1414
    If I may butt in...
    I think the problem with SELECT * is that you generally don't need to retrieve data from every column... Now if you do need every column then SELECT * should be fine... It's just a speed issue.

    Please do correct me if I'm wrong

  7. #6
    Member
    Join Date
    Apr 2003
    Posts
    34
    Member #
    1102
    $result = mysql_query("SELECT * FROM wplanet_click_counter WHERE id='$id'");


    try that and see if it works... you left out a ' after '$id
    http://www.huanderson.com
    http://www.huanderson.com/portfolio/

  8. #7
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    Code:
    <?php
    
    $result = mysql_query("SELECT id FROM wplanet_click_counter WHERE id='$id");
    $count = mysql_num_rows($result);
    
        
    
        $update = "UPDATE wplanet_click_counter SET count='$count' WHERE id='$id' ";
    
    mysql_query($update);
    
            
    
    $sql = mysql_query("SELECT url, id FROM wplanet_click_counter WHERE id='$id'");
    
    $row = mysql_fetch_array($result);
    
    $url = $row['url'];
    
    echo "<script language='JavaScript'>document.location.href=' $url '</script>";
    
    mysql_close();
    
    ?>


    The error is that you didn't select a column that you used (id) in the last query. I also tidied up a bit...
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  9. #8
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    I fixed that
    I had $row = mysql_fetch_array($result); and I should have $row = mysql_fetch_array($sql);

    Here is the code ....
    PHP Code:
    $result mysql_query("SELECT id,url,count FROM wplanet_click_counter WHERE id='$id'");
    $row mysql_fetch_array($result);

        
    $id=$row['id'];
        
    $count=$row['count'];
        
    $count $count 1;
        
    $numrows mysql_num_rows($result);
        
    $update "UPDATE wplanet_click_counter SET count='$count' WHERE id='$id' ";
        
    $updatesql mysql_query($update);
            
    $sql mysql_query("SELECT id,url FROM wplanet_click_counter WHERE id='$id'");
    $row mysql_fetch_array($sql);
    $id $row['id'];
    $url $row['url'];
    $numrows mysql_num_rows($result);
    header("Location: $url");
    mysql_close(); 
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:00 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com