Creating Unique Web Pages from a MySQL Database

I am very new to web development (I have limited experience with HTML). I am creating a discussion site. Currently, each discussion is stored in a MySQL database. When a user sends information to the database, I want to create a new page containing their debate, as well as the ability to comment and rate it.

The problem I am facing is that, from the research that I have done so far, I cannot find a solution to create a new web page for each discussion. Anyone have any suggestions on how to write data to a unique web page?

Thanks George

+4
source share
3 answers

Suppose you are using PHP and MySQL.

I will keep it as simple as possible, perhaps these files are needed in a basic example plus your reliable SQL explanatory tables (debate, comments, etc.).

  • /debatelist.php | Dipslays all debates have the form to create a discussion.
  • /debateprocessor.php | Your all-in-one data file.
  • /debate_detail.php | A page with detailed information that indicates a debate index.

DISCUSSION CREATION FORM

<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 it will send the form data to the .php discussion processor, where we will sanitize and prefix.

$ _ GET ['action'] = "create" #this tells us that we are creating a discussion $ _GET ['debate_name'] = "SomeDebate"

debateprocessor.php - you want to pull this into:

 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'"); } 

Pay attention to the action if ($ action == 'foo') {// do something; } - this will allow you to process updates (comments, edit discussion names, etc.) all in one file. other values ​​for actions in forms can be "edit", "add_comment", etc. - you can have separate files to do all this, but it allows you to do all this. All you need to do is add to elseifs or other if statements, as described above, for each action to modify the table.

So, showing your debate, you will have something like a main debate list in the table, let's say that you have

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++; } 

This will list debate names with a link to ea. debate_detail.php for this discussion by the PC, debate identifier. In this file, you should use a similar combination of SELECT (ONLY USE) WHERE debate_id = 'xyz' and most likely use JOIN tables as comments, etc. On debate_id = 'zyx' = debate_id = 'zyx'.

+2
source

You have a script that looks at the requested URI (the query string is the easiest place to look for foo.php?debate=1 β†’ $_GET['debate'] ) and use this to get some information that uniquely identifies the desired discussion ( for example, the column value that you use for the primary key in the database table).

Look at this line in the database and display the content on the page.

(Make sure that you send data to the database in a way that protects against SQL Injection, and that you do not return user input back to HTML without escaping or sanitizing it for XSS protection.)

+1
source

You need to use a template engine such as PHP. For each discussion, you pass a different query string, for example, for debate id 1, you may have

 www.example.com/debates?id=1 

In your php code, you can check the value of this query parameter and use it to extract corruption information from the database, which allows you to dynamically create a page.

0
source

All Articles