Hello Everyone, I’m new here. Recently I just create a psudo-news system and I am curious if I might get some feed-back on what to do better. Thank you for your time. And any suggestions would be greatly appreciated.
-Teh Riddler
Form.html:
[code]
Title: | |
Post: | |
MySql Table
$query = ("CREATE TABLE news(
id INT(4) NOT NULL AUTO_INCREMENT,
datim VARCHAR(255) NOT NULL,
title TEXT(65000) NULL,
post TEXT(65000) NOT NULL,
PRIMARY KEY(id))
");
Insert.php
[code]<?php
$date = $_POST[‘date’];
$title = $_POST[‘title’];
$post = $_POST[‘post’];
//date format
$date = date($date);
//database insert
$user = “user”;
$pass = “pass”;
$db = “db”;
mysql_connect(“localhost”,$user,$pass);
@mysql_select_db("$db") or die(“Unable to Select Database”);
$query = “INSERT INTO news VALUES(
‘’,’$date’,’$title’,’$post’)”;
if($result = mysql_query($query)){
echo “Data entered!”;
}else{
echo “Mysql Error!”.mysql_error();
}
mysql_close();
?>
Back[/code]
Insert2.php
[code]<?php
//database connect
$user = “user”;
$pass = “pass”;
$db = “db”;
$nl = “n”;
mysql_connect(“localhost”,$user,$pass);
@mysql_select_db("$db") or die(“Unable to Select Database”);
$query = (“SELECT * FROM news ORDER BY id DESC”);
$result = mysql_query($query);
//open or create news text file
$file = “news.txt”;
$fh = fopen("$file", ‘w’);
//get the number of rows
$num = mysql_numrows($result);
$i = 0;
while($i < $num){
$date = mysql_result($result,$i,‘datim’);
$title = mysql_result($result,$i,‘title’);
$post = mysql_result($result,$i,‘post’);
$l1 = “
$l2 = "
$date
".$nl;$l3 = "
$title
".$nl;$l4 = "
$post
".$nl;$l5 = “
$news = $l1.$l2.$l3.$l4.$l5;
fwrite($fh, $news);
$i++;
}
//dc database
mysql_close();
//close text file
fclose($fh);
?>
Submit another News Item
Return to the Site
View News Items[/code]
Index.php
[code]<?php
function news(){
$file = “news.txt”;
$fh = fopen($file, ‘r+’);
$fs = filesize($file);
$fr = fread($fh, $fs);
fclose($fh);
echo $fr;
}
?>
<?php news(); ?>[/code]