Jump to content

Problem with $_GET


AV

Recommended Posts

Hello,

I have been playing around with a script which makes that when you click link, it goes to:

localhost/redirect/123

where 123 is ID of an article. After that it redirects you to the outside link.

I have created this:

if(isset($_GET['action'])) {
if($_GET['id']) {
        $id = (int)$_GET['id'];
        $query = mysql_query("SELECT * FROM news WHERE id = '$id'");
        while($row = mysql_fetch_array($query)) { 
             $insert = "UPDATE news SET views = views + 1";
             mysql_query($insert); 
             header("Location:". $row['url']);
        }
    }
}
//[...]
echo "<a href=\"{$???}\"></a>

Problem is I have no idea how I can finish that script. Can someone help me?

 

Link to comment
Share on other sites

try

 

<?php
if(isset($_GET['action']||$_GET['id'])) {

$id = (int)$_GET['id'];
       $query = mysql_query("SELECT * FROM news WHERE id = '$id'");
while($row = mysql_fetch_array($query)) { 
            $insert = "UPDATE news SET views = views + 1";
            mysql_query($insert); 
            header("Location:". $row['url']);
       }
   }

?>

Link to comment
Share on other sites

Here is whole code btw:

<?php
//redirect script
if(isset($_GET['id'])) {$id = (int)$_GET['id'];
$query = mysql_query("SELECT * FROM news WHERE id = '$id'");
while($row = mysql_fetch_array($query)) { 
$insert = "UPDATE news SET views = views + 1";
mysql_query($insert); 
header("Location:". $row['url']);
}
}
//redirect script end
$row = mysql_num_rows($result);

for ($i=0;$i<$row;$i++) {
$array = mysql_fetch_array($result);
print "<td><a href=\"/redirect/$id\">{$array["title"]}</a>";
}

?>

rarebit, I try to call function by

localhost/redirect/

,your method doesn't work.

darkfreaks, same as before :/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.