fetch mysql data and create its page
Please see this code, this code is sending every data that has been entered in the field and then fetching it and showing it on the screen.
i want it to create a new page for every data it fetch,
for example,
suppose a code fetch a text 'ABC' from mysql , i want my code to create a new page for this page called 'ABC.html' and show the link on the screen, this should be done with every fetched data.
example -> http://FBlykes.com
here is my code,
<?php
$name=$_POST['name'];
mysql_conne开发者_如何学编程ct("localhost", "root", "") or die(mysql_error());
mysql_select_db("quotes") or die(mysql_error());
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="name">
<input type="submit" value="GO" name="submit">
</form>
<?php
if(isset($_POST['submit']))
{
mysql_query ("INSERT INTO example (name) VALUES('$name')") or die(mysql_error());
}
//Fetching
$query = "SELECT * FROM example ORDER BY id DESC";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<li>";
echo $row['name'];
echo "</li>";
}
?>
Sanitize database input with htmlspecialchars at least. You must use mod_rewrite, in order to generate pages like ABC.html, ABC is in fact a parameter that you pass to PHP script eg page.php?name=ABC...
RewriteRule ^(.*).html$ page.php?name=$1
You should use this rule as last rule if you have other .html pages. PHP script should then fetch "ABC" (whatever it is) from database and print it as HTML page.
精彩评论