从MySQL数据库创建独特的网页

时间:2021-11-12 23:28:14

I'm very new to web development (I have limited experience with HTML). I'm creating a debate website. Currently, each debate is stored in a MySQL database. When the user submits the information to the database, I want a new page to be created, that contains their debate, and the ability to comment and rate it.

我对Web开发很新(我对HTML的经验有限)。我正在创建一个辩论网站。目前,每个辩论都存储在MySQL数据库中。当用户将信息提交给数据库时,我想要创建一个新页面,其中包含他们的辩论,以及评论和评级的能力。

The problem I'm having is that, from the research I've done so far, I'm not finding a solution to having a new web page for each debate. Does anyone have any suggestions on how to write the data to a unique web page??

我遇到的问题是,从我迄今为止所做的研究来看,我找不到为每次辩论都有一个新网页的解决方案。有没有人对如何将数据写入一个独特的网页有任何建议?

Thanks, George

3 个解决方案

#1


2  

Let's assume you are using PHP and MySQL.

假设您使用的是PHP和MySQL。

I will keep this very simple as possible probably need these files in a basic example plus your hopefull explanatory SQL tables (debates, comments, etc).

我会尽可能地保持这个非常简单,可能需要这些文件在一个基本的例子中加上你希望解释的SQL表(辩论,评论等)。

  • /debatelist.php | Dipslays all debateshas a form to create a debate
  • /debatelist.php | Dipslays所有辩论都有一种形式可以引发辩论

  • /debateprocessor.php | Your 'all in one' data manipulation file.
  • /debateprocessor.php |您的“一体化”数据操作文件。

  • /debate_detail.php | Your detail page where the index of debates points to.
  • /debate_detail.php |辩论索引指向的详细信息页面。

Form to CREATE A DEBATE

表格创建辩论

<form action='debateprocessor.php' action='POST'>
<input type='hidden' name='action' value='create'/>
<input type='text name='debate_name'/>
/// Other inputs - debate topic, debate author, subject etc? same as above
</form>

then that would send the form data to debateprocessor.php where we'd sanitize and prepit.

然后,这会将表格数据发送到debateprocessor.php,我们将在那里进行清理和预制。

$_GET['action']="create" #this tells us we are creating the a debate $_GET['debate_name']="SomeDebate"

$ _GET ['action'] =“创造”#this告诉我们我们正在创建辩论$ _GET ['debate_name'] =“一些辩论”

debateprocessor.php - you'd want to to pull that in:

debateprocessor.php - 你想把它拉进去:

if (mysql_real_escape_text($_GET['action'])) == 'create'){
    $debate_name = mysql_real_escape_text($_GET['debate_name']);
    //sanitize other variables as above

    //Insert debate name
    mysql_query=("INSERT INTO debates (debate_id,debate_name) VALUES ('$debate_name'");

}

Note the action if($action == 'foo'){ //do something; } statement - this would allow you to handle updates (comments, editing debate names etc) all in one file. other values for action in forms could be 'edit', 'add_comment' etc - you could have separate files to do all this but this allows you to do it all one. All you'd do is add on elseifs or other if statements like above for each action to modify a table.

注意动作如果($ action =='foo'){//做某事; }语句 - 这将允许您在一个文件中处理更新(注释,编辑辩论名称等)。表单中其他值的操作值可以是“编辑”,“添加注释”等 - 您可以使用单独的文件来执行所有操作,但这样可以让您完成所有操作。您要做的就是为每个修改表的操作添加上述elseif或其他if语句。

So displaying your debates you'd have something like a master list of debates in a table, say you had

因此,你可以在表格中展示你的辩论,就像表格中的主要辩论列表一样

debatelist.php

<?
$getDebates = mysql_query("SELECT * FROM debates";); 
$rowNum = 0;

while($row = mysql_fetch_array($getDebates))
{
    $thisDebate = $row['debate_name'];
    $thisDebateID = $row['debate_id'];;

    echo
    "
        <tr>
        <td>
           <a href='debate_detail.php?debateid=$thisDebateID'>
            $thisDebate
        </a>
        </td>

    </tr>
    ";
    $rowNum++;
}

That would output a list of debate names with a link to ea. debate_detail.php page for a given debate pulled by the PK, debate ID. In that file you'd use a similar combination of SELECT (ONLY USE 'WHERE debate_id = 'xyz' and would likely JOIN tables like comments etc on debate_id='zyx' = debate_id='zyx'.

这将输出一个辩论名称列表,其中包含指向ea的链接。辩论ID,由辩论ID提出的辩论的辩论_detail.php页面。在该文件中,您将使用SELECT的类似组合(仅使用'WHERE debate_id ='xyz',并且很可能在comments_id ='zyx'= debate_id ='zyx'上加入表格,如评论等。

#2


1  

Have a script that looks at the requested URI (the query string is the simplest place to look foo.php?debate=1$_GET['debate']) and use that to get a piece of information that uniquely identifies the debate you want (e.g. the value of the column you use for the primary key in the database table).

有一个查看请求的URI的脚本(查询字符串是查看foo.php的最简单的地方?辩论= 1→$ _GET ['辩论'])并使用它来获取一条唯一标识辩论的信息想要(例如,您用于数据库表中主键的列的值)。

Look up that row in the database, and output the content to the page.

在数据库中查找该行,并将内容输出到页面。

(Make sure you send data to the database in a way that defends against SQL Injection, and that you don't echo user input back to the HTML without escaping or sanitising it to defend against XSS).

(确保以防止SQL注入的方式将数据发送到数据库,并且不将用户输入回送到HTML而不转义或清理它以防御XSS)。

#3


0  

You need to use a templating engine such as PHP. For each debate you pass a different query string for example for debate id 1 you might have

您需要使用PHP等模板引擎。对于每个辩论,您传递一个不同的查询字符串,例如您可能拥有的辩论ID 1

www.example.com/debates?id=1

In your php code you can then check the value of this query parameter and use it to extract the corrwect information from the databse, allowing you to dynamically create the page.

在您的PHP代码中,您可以检查此查询参数的值,并使用它从数据库中提取corrwect信息,允许您动态创建页面。

#1


2  

Let's assume you are using PHP and MySQL.

假设您使用的是PHP和MySQL。

I will keep this very simple as possible probably need these files in a basic example plus your hopefull explanatory SQL tables (debates, comments, etc).

我会尽可能地保持这个非常简单,可能需要这些文件在一个基本的例子中加上你希望解释的SQL表(辩论,评论等)。

  • /debatelist.php | Dipslays all debateshas a form to create a debate
  • /debatelist.php | Dipslays所有辩论都有一种形式可以引发辩论

  • /debateprocessor.php | Your 'all in one' data manipulation file.
  • /debateprocessor.php |您的“一体化”数据操作文件。

  • /debate_detail.php | Your detail page where the index of debates points to.
  • /debate_detail.php |辩论索引指向的详细信息页面。

Form to CREATE A DEBATE

表格创建辩论

<form action='debateprocessor.php' action='POST'>
<input type='hidden' name='action' value='create'/>
<input type='text name='debate_name'/>
/// Other inputs - debate topic, debate author, subject etc? same as above
</form>

then that would send the form data to debateprocessor.php where we'd sanitize and prepit.

然后,这会将表格数据发送到debateprocessor.php,我们将在那里进行清理和预制。

$_GET['action']="create" #this tells us we are creating the a debate $_GET['debate_name']="SomeDebate"

$ _GET ['action'] =“创造”#this告诉我们我们正在创建辩论$ _GET ['debate_name'] =“一些辩论”

debateprocessor.php - you'd want to to pull that in:

debateprocessor.php - 你想把它拉进去:

if (mysql_real_escape_text($_GET['action'])) == 'create'){
    $debate_name = mysql_real_escape_text($_GET['debate_name']);
    //sanitize other variables as above

    //Insert debate name
    mysql_query=("INSERT INTO debates (debate_id,debate_name) VALUES ('$debate_name'");

}

Note the action if($action == 'foo'){ //do something; } statement - this would allow you to handle updates (comments, editing debate names etc) all in one file. other values for action in forms could be 'edit', 'add_comment' etc - you could have separate files to do all this but this allows you to do it all one. All you'd do is add on elseifs or other if statements like above for each action to modify a table.

注意动作如果($ action =='foo'){//做某事; }语句 - 这将允许您在一个文件中处理更新(注释,编辑辩论名称等)。表单中其他值的操作值可以是“编辑”,“添加注释”等 - 您可以使用单独的文件来执行所有操作,但这样可以让您完成所有操作。您要做的就是为每个修改表的操作添加上述elseif或其他if语句。

So displaying your debates you'd have something like a master list of debates in a table, say you had

因此,你可以在表格中展示你的辩论,就像表格中的主要辩论列表一样

debatelist.php

<?
$getDebates = mysql_query("SELECT * FROM debates";); 
$rowNum = 0;

while($row = mysql_fetch_array($getDebates))
{
    $thisDebate = $row['debate_name'];
    $thisDebateID = $row['debate_id'];;

    echo
    "
        <tr>
        <td>
           <a href='debate_detail.php?debateid=$thisDebateID'>
            $thisDebate
        </a>
        </td>

    </tr>
    ";
    $rowNum++;
}

That would output a list of debate names with a link to ea. debate_detail.php page for a given debate pulled by the PK, debate ID. In that file you'd use a similar combination of SELECT (ONLY USE 'WHERE debate_id = 'xyz' and would likely JOIN tables like comments etc on debate_id='zyx' = debate_id='zyx'.

这将输出一个辩论名称列表,其中包含指向ea的链接。辩论ID,由辩论ID提出的辩论的辩论_detail.php页面。在该文件中,您将使用SELECT的类似组合(仅使用'WHERE debate_id ='xyz',并且很可能在comments_id ='zyx'= debate_id ='zyx'上加入表格,如评论等。

#2


1  

Have a script that looks at the requested URI (the query string is the simplest place to look foo.php?debate=1$_GET['debate']) and use that to get a piece of information that uniquely identifies the debate you want (e.g. the value of the column you use for the primary key in the database table).

有一个查看请求的URI的脚本(查询字符串是查看foo.php的最简单的地方?辩论= 1→$ _GET ['辩论'])并使用它来获取一条唯一标识辩论的信息想要(例如,您用于数据库表中主键的列的值)。

Look up that row in the database, and output the content to the page.

在数据库中查找该行,并将内容输出到页面。

(Make sure you send data to the database in a way that defends against SQL Injection, and that you don't echo user input back to the HTML without escaping or sanitising it to defend against XSS).

(确保以防止SQL注入的方式将数据发送到数据库,并且不将用户输入回送到HTML而不转义或清理它以防御XSS)。

#3


0  

You need to use a templating engine such as PHP. For each debate you pass a different query string for example for debate id 1 you might have

您需要使用PHP等模板引擎。对于每个辩论,您传递一个不同的查询字符串,例如您可能拥有的辩论ID 1

www.example.com/debates?id=1

In your php code you can then check the value of this query parameter and use it to extract the corrwect information from the databse, allowing you to dynamically create the page.

在您的PHP代码中,您可以检查此查询参数的值,并使用它从数据库中提取corrwect信息,允许您动态创建页面。