Forum Moderators: coopster

Message Too Old, No Replies

Unique urls for individual posts in mysql database

?id=249-need some help

         

mitman

12:27 am on Jul 10, 2009 (gmt 0)

10+ Year Member



I've looked around for something similar to this, but I couldn’t find anything. I have a script that allows users to post various information (comments, name etc.) to a MYSQL database. Each post is assigned a unique id when it is entered into the database.

What I am trying to do now is retrieve that data and give each post its own unique url (For example, one post could have the url http://www.example.com/showresults.php?id=249). If one was to go to that link, they would see a specific post and that url would be unique to that post. I understand that you have to use variables but I don’t quite get how I would go about doing this. Any help would be greatly appreciated.

PokeTech

3:56 am on Jul 10, 2009 (gmt 0)

10+ Year Member



<?php
require 'dbconnectfile.php';

$query = mysql_query("SELECT post FROM posts_table WHERE id='$_GET[id]'");
$row = mysql_fetch_assoc($query);

echo $row['post'];
?>

That should do it assuming that is what you named your fields. Just place it in the results page and it should work. Just change it around to match your layout and what not.

coopster

1:39 pm on Jul 10, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



And welcome to WebmasterWorld, mitman.

One piece of advice in that query example ... ALWAYS edit/escape user-supplied data. I would edit check it first to be certain it contains exactly what you expect, an integer value. I then run it through the mysql_real_escape_string [php.net] for good measure.