The script contains 2 files. add.html, and news.php. Add.html is the HTML document with the form to fill out. News.PHP displays the news, and also has a switch function in there that stores the news in the MySQL database, and reads off it. Here I will post the script of each.
Add.html
Code: Select all
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Title of News</title>
</head>
<body>
<form action="new.php?act=add" method="post">
<p>Title of News :<input type="text" name="title" size="56"></p>
<p>News : </p>
<p><textarea rows="9" name="text" cols="60"></textarea></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>News.php
Code: Select all
<?
SWITCH($HTTP_GET_VARSїact]) {
case "add":
$title = $_POSTї'title'];
$text = $_POSTї'text'];
mysql_connect('localhost','mySQLusername','mySQLpassword);
mysql_select_db('Databasename');
if(empty($title) || empty($text)) exit("You didnt completley fill out the form! Go back");
$title = addslashes($title); $text = addslashes($text);
mysql_query("INSERT INTO news (title,text) VALUES ('$title','$text')");
print "You have succesfully created a new story!";
break;
// Code above stores the new story in the databse
default:
mysql_connect('localhost','mySQLusername','mySQLpassword');
// logs into the mysql database
mysql_select_db('Databasename');
// name of the dedicated databse
$query = mysql_query('SELECT * FROM news');
// gets all information in the news table
while($news = mysql_fetch_array($query)) {
echo "Title:" . $newsї'title'] . "n";
echo $newsї'text'] . "n";
// This displays news.php because it is default. This reads news out of the database.
}
?>Anyone have any ideas?
Thanks!