Jump to content

help this code wont echo the link in my database can anyone help


mattm1712

Recommended Posts

<html>

<?php

 

include connect.inc;

 

$id = $_GET['id'];

 

mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$id'");

 

$sql = mysql_query("SELECT link FROM count WHERE id='$id'");

$fetch = mysql_fetch_row($sql);

 

$result = mysql_query($sql);

 

while($row = mysql_fetch_array($result))

{

    echo "Name :{$row['id']} <br>" .

        "Subject : {$row['link']} <br>" .

        "Message : {$row['count']} <br><br>";

}

 

mysql_close();

?>

 

<a href='/index.php?id=1'>link1</a>

<a href='/index.php?id=2'>link2</a>

</html>

You've got mysql_query calls and fetch calls mixed up. Try

 

<?php

include 'connect.inc';

$id = $_GET['id']; // if this is an integer change it to $id = (int)$_GET['id']  which will force as an int, and prevent SQL injection

mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$id'");

$sql = "SELECT link FROM count WHERE id='$id'";

$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
{
    echo "Name :{$row['id']} <br>" .
         "Subject : {$row['link']} <br>" .
         "Message : {$row['count']} <br><br>";
}

mysql_close();
?> 

 

Also, don't use .inc as a file extension for a PHP include. Unless you have the web server setup to deny direct access, anybody could just browse directly to that file and the contents will be displayed - i.e database credentials.

 

It looks like the id field is an integer PK for the table, if so you don't need a while loop if there will only ever be 1 record with that id.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.