Jump to content


Photo

Click Counter


  • Please log in to reply
5 replies to this topic

#1 miligraf

miligraf
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 28 April 2006 - 10:26 PM

Hello, i have a click counter that works with a link like this: http://www.yourdomain.com/tutorial.php?id=1 But when i click the link it takes me to that URL and not to the one saved in the SQL table, so i guess its the tutorial.php. Ive been trying to make it work but i cant :(

tutorial.php

<?
include ('conbd.php');

$query = mysql_query ("SELECT * FROM tutoriales WHERE id='$id'");

while ($row = mysql_fetch_row($query))
{

$id = $row[0];
$enlace = $row[5];

header('Location: '.$enlace);

}

mysql_query ("UPDATE tutoriales SET clics = clics + 1 WHERE id='$id'");
?>

Thanks for your help!

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 29 April 2006 - 12:33 PM

Add this after the include:
$id=$_GET['id'];

Btw, read about SQL injections, because your script is unsecure.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 miligraf

miligraf
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 30 April 2006 - 04:44 AM

Negative Orio, still doesnt work :-(

And thx for the suggestion!

I would also like an easy-to-learn php manual, so i will have a better sense on figuring php things out, ty.

#4 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 30 April 2006 - 09:57 AM

Injection proof:
$id = $row[0];
$enlace = $row[5];

$id = mysql_escape_string(striptags($id));
$enlace = mysql_escape_string(striptags($enlace));

PHP is my friend (=

#5 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 30 April 2006 - 01:48 PM

Maybe its the:
mysql_query ("UPDATE tutoriales SET clics = clics + 1 WHERE id='$id'");

Thats got to be-
$newclics=$clics+1;
mysql_query ("UPDATE tutoriales SET clics='$newclics' WHERE id='$id'");

Orio.
Think you're smarty?

(Gone until 20 to November)

#6 miligraf

miligraf
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 30 April 2006 - 08:21 PM

Doesnt work either...ive checked the other php where you click the link but it works fine, its this tutorial.php that isnt working, it doesnt add the click or redirects you to the URL stored in the database. I dunno what happened, it was working fine before but now it doesnt.

Edit: i already figured out the problem, thx for your help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users