- Joined
- Apr 22, 2008
- Messages
- 34
- Reaction score
- 0
Whos Logged In?
News System For Website
Display The News, Include This Somewhere (post.php)
Post The News (put this somewhere)
Post The News(post.php)
News Database
PHP:
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("odinms", $con);
echo 'The following users are online:';
$result = mysql_query("SELECT name
FROM accounts
WHERE loggedin=1");
while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['online'];
echo ", ";
}
mysql_close($con);
?>
News System For Website
Display The News, Include This Somewhere (post.php)
PHP:
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("odinms", $con);
$result = mysql_query("SELECT * FROM news ORDER BY id DESC limit 15");
while($row = mysql_fetch_array($result))
{
echo "<br><b><font size='5' face='sans-serif'><span id='jiggle0' class='jc'>" . $row['title'] . "</span></b><hr></font>";
echo "<font size='3' face='sans-serif'>" . $row['message'] . "</font><br>";
}
mysql_close($con);
?>
PHP:
<form action="post.php" method="POST">
Title:<input type=text name=title maxlength="30" style=" font-size:.99em;border:2px inset pink;"><br>
Message:<textarea scrollbar=no name=message maxlength="300" rows="10" cols="50"style=" font-size:.99em;border:2px inset pink;"></textarea><br>
<input type="submit" value='Post Main' style=" font-size:.99em;border:2px inset pink;"></td></tr>
</form>
Post The News(post.php)
PHP:
<?php
$title = $_POST['title'];
$message = $_POST['message'];
$host['naam'] = 'localhost';
$host['gebruikersnaam'] = 'root';
$host['wachtwoord'] = 'root';
$host['databasenaam'] = 'odinms';
$db = mysql_connect($host['naam'], $host['gebruikersnaam'], $host['wachtwoord']) OR die ('Cant connect to the database');
mysql_select_db($host['databasenaam'], $db);
if($message == ""){
echo 'Enter a message mr.dum';
exit();
}elseif($title == ""){
echo 'You have to enter a title you stupid idiot!!';
exit();
}else{
$d = 'INSERT INTO news (title, message) VALUES ("'.$title.'", "'.$message.'")';
mysql_query($d) OR die (mysql_error());
echo 'Message Posted (normal)<a href="http://yoursite.com">Back</a>';
}
?>
Code:
DROP TABLE IF EXISTS `odinms`.`news`;
CREATE TABLE `odinms`.`news` (
`title` text character set latin1 NOT NULL,
`message` text character set latin1 NOT NULL,
`id` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 COLLATE=latin1_bin;

