简体   繁体   English

URL重写和url参数

[英]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. 我是php和mysql的菜鸟,希望了解它的工作原理。 That's why I decided to make a website about a particular theme. 这就是为什么我决定建立一个有关特定主题的网站的原因。 That's the best practice to learn these 2 languages... 这是学习这两种语言的最佳实践...

So, 所以,

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. 我曾经使每个视频都具有唯一的网页...现在,我拥有300多个页面的视频内容,我想将所有这些内容带入数据库并将它们全部放在一个模板网页中。

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. 我想用mysql请求做一些URL重写。

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. Dreamweaver告诉我,合成器上没有错误,但是当我预览它时(WAMP),它一直向我显示错误,直到摆脱了“ p”参数。 Hereunder, I join you the code i'm using. 在下文中,我加入了我正在使用的代码。

    <?php
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);

if($data["url"]!=$_GET["url"])
{
    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; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1 ERROR 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ LIMIT 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. URL参数也位于我的数据库中,并且php脚本调用数据库以检索URL,并使它看起来像一个唯一的网页。

Oh and sorry for my English... 哦,抱歉我的英语...

Thanks a lot. 非常感谢。

Try 尝试

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

try echo $_GET["id"]; 尝试echo $ _GET [“ id”]; before sql and check if you are getting any value. 在sql之前,并检查是否获得任何值。 And also learn "PDO" it is better than using direct sql statements or as Joyce said use escape_string. 并且还学习“ PDO”,这比使用直接sql语句或乔伊斯所说的使用escape_string更好。

Change your line: $sql = "SELECT * FROM videos WHERE id=$id LIMIT 1"; 更改您的行:$ sql =“ SELECT * FROM视频WHERE id = $ id LIMIT 1”;

TO THIS: $sql = "SELECT * FROM videos WHERE id='".$id."' LIMIT 1"; 到此为止:$ sql =“ SELECT * FROM id ='”。$ id。“'LIMIT 1”的视频;

Your SELECT is selecting the string '$id' rather than the php variable $id. 您的SELECT选择的是字符串'$ id',而不是php变量$ id。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM