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>

Link to comment
Share on other sites

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.

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.