URL rewriting and url parameter

I've been building my website from the very beginning until today with no framework or WYSIWYG software. I now realize that the way I made it could have been a lot simplier.

I'm a noob in php and mysql and wish to understand how it works. That's why I decided to make a website about a particular theme. That's the best practice to learn these 2 languages...


My website goes about video content with daily updates.

I use to make per video a unique webpage... Now I've more than 300 pages of video content and I want to bring all this content into my database and put it all in one template webpage.

When I want to apply a change, I have to open all those webpages and make on each page the needed changes. Fortunatelly, the search en replace box helps me.

I just wanted to do something on the website that could make my routine and work a lot faster and easier.

I'd like to do some url rewriting with mysql requests.

I'm working on a piece of code, but I can't find what goes wrong with that. Dreamweaver tells me that there's no error on the synthax, but when I preview it (WAMP) , it keeps showing me an error until a get rid of the 'p' paramater. Hereunder, I join you the code i'm using.

include "connect.php";
$id = $_GET["id"]; 
$sql = "SELECT * FROM videos WHERE id=$id LIMIT 1"; //mysql tells me there's a error near LIMIT 1
$req = mysql_query($sql) or die( mysql_error()." ERROR");
$data = mysql_fetch_assoc($req);

    header("location:/video/atest.php/".$data["id"]."-".$data["url"]); //if the URL is altered, it will be immediatelly fixed thanks to this function

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1 ERROR

Thanks to that I will be able to insert on my database every piece of content for each unique video > title, description, ... without the need to make a thousand of changes and upload new webpages.

the URL parameters are also on my database and the php scripts makes the call to the database to retrieve the URL and make this look like a unique webpage.

Oh and sorry for my English...

Thanks a lot.



$id = mysql_real_escape_string($_GET["id"]); 
$sql = "SELECT * FROM videos WHERE id=$id LIMIT 1";

try echo $_GET["id"]; before sql and check if you are getting any value. And also learn "PDO" it is better than using direct sql statements or as Joyce said use escape_string.

Change your line: $sql = "SELECT * FROM videos WHERE id=$id LIMIT 1";

TO THIS: $sql = "SELECT * FROM videos WHERE id='".$id."' LIMIT 1";

Your SELECT is selecting the string '$id' rather than the php variable $id.

Need Your Help

bash script getting the value from a variable of the form var$[id]

bash shell

This is the first time Im using a shell script ( #!/bin/sh ) and Ive been working my way through it reading tutorials and the like but Im stuck on this reading and writing values of a key..

Should pointers be used to reduce header dependencies?

c++ pointers circular-dependency forward-declaration

When creating a class that is composed of other classes, is it worthwhile reducing dependencies (and hence compile times) by using pointers rather than values?