Logo
Dynamic Page Content From Links
Online Now: 2
Snippet Code
This shows how to load a specific file into the page by clicking on a link.

links.php


<a href="links.php?id=1">File 1</a>
<a href="links.php?id=2">File 2</a>
<a href="links.php?id=3">File 3</a>
<?php
// Load the database connections
include 'db.php';
//check to see if one of the links were clicked
echo '<div>';
if(isset(
$_GET['id'])){
    
// Make a safe string
    
$id mysql_real_escape_string($_GET['id']);
    
// Query the database
    
$sql mysql_query("SELECT * FROM table_name WHERE id='$id'");
    if(
mysql_num_rows($sql) == 1){
        
// If one row was found, create an array of the row
        
$row mysql_fetch_array($sql);
        
// echo the column 'content' (change 'content' to your column name)
        
echo '<p>'.$row['content'].'</p>';
    }else{
        
// Row was not found
        
echo '<p>File Not Found.</p>';
    }
}else{
    
// the id parameter in the url was not set
    
echo '<p>Invalid URL.</p>';
}
echo 
'</div>';
?>
 
Snippet Comments

Add Your Comment

Bennett
2011-03-26 18:16:24
You don't need to get information from the database to use query-string URLs. :-X
Dan
2010-12-09 08:22:48
@Sam Yong: That can't be man... The content is pulled from the database, not in the query string, for one... The only thing it references in the query is the ID, and that's escaped...
admin
2010-03-23 00:00:00
I have updated this snippet, tell me what you think!
Sam Yong
2009-07-25 00:00:00
This is a very dangerous code. it might just cause your whole site to be hacked because you can put anything to $_GET['content']. Thus people can just move to your root directory and read your protected files e.g. application configuration file (containing mysql passwords for example)

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: Novice
Current Score: 2.95
Total votes: 339
Total Views: 7493

Other top snippets by admin:

1. JPEG to ASCII Converter
2. Add (th, st, nd, rd, th) to the end of a number
3. AJAX Quickie
4. Simple Image CAPTCHA
5. Logout Inactive User

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative