Create all three files, input the php code into each file that is listed. Then change the database info in ALL three files.
$host = "localhost";
$user = "your-username";
$pass = "your-password";
$dbname = "your-username_your-database";
DO NOT edit $conn = mysql_connect($host, $user, $pass);
Found an error? Leave a comment :-)
Feel free to edit or add some addons, However I'm not gonna help with ANY addons.
FIRST Creating table:
File name: 'createtable.php'
<?php
$host = "localhost";
$user = "your-username";
$pass = "your-password";
$dbname = "your-username_your-database";
$conn = mysql_connect($host, $user, $pass);
mysql_select_db($dbname);
mysql_query("DROP TABLE news"); /* ADDED: just in case */
$query = "CREATE TABLE `news` (`id` int(10) unsigned NOT NULL auto_increment, `news` TEXT NOT NULL default '', PRIMARY KEY (`id`))";
mysql_query($query);
mysql_close($conn);
?>
Run it once!
SECOND Process Page:
File name: 'index.php'
<?php
/* isset() is used to know if the variable exists */
/* $_POST array is created/updated after a submit */
if (isset($_POST['News']))
{
$host = "localhost";
$user = "your-username";
$pass = "your-password";
$dbname = "your-username_your-database";
$conn = mysql_connect($host, $user, $pass);
mysql_select_db($dbname);
$query = "INSERT !NTO news VALUES (NULL, '".$_POST['News']."')";
mysql_query($query) or die ("formInput error: $query");
mysql_close($conn);
}
?>
<!-- HTML CODE -->
<html>
<head>
<title>Index</title>
</head>
<body>
<h1>Index</h1>
<form name="New" action="./index.php" method="post">
<textarea name="News" cols="45" rows="10"></textarea>
<br><input type="submit" value="Submit">
</body>
</html>
THIRD News Section:
File name: 'news.php'
<?php
$host = "localhost";
$user = "your-username";
$pass = "your-password";
$dbname = "your-username_your-database";
$conn = mysql_connect($host, $user, $pass);
mysql_select_db($dbname);
$query = "SELECT * FROM news";
$result = mysql_query($query);
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$return[$i] = $row["news"];
$i++;
}
mysql_free_result($result);
mysql_close($conn);
?>
<!-- HTML CODE -->
<html>
<head>
<title>News Section</title>
</head>
<body>
<h1>News Section</h1>
<?php
for ($i = 0; $i < count($return); $i++)
{
?>
<p><?= $return[$i] ?></p>
<?php
}
?>
</body>
</html>