hi guys,
im just trying to get a simple news posting script working but after i submit the form the page thats meant to display the database is just blank, i have copied the code below, can anyone help??
(dbconnect.php)
<?php
$username = "marginex";//your username
$password = "steven";//your password
$host = "localhost";//your mySQL server
$database = "newscms";//The name of the database your table is in
mysql_connect($host,$username,$password) or die("Error connecting to Database!<br>" . mysql_error());//connect, but if there is a problem, display an error message telling why there is a problem
mysql_select_db($database) or die("Cannot select database!<br>" . mysql_error());//Choose the database from your mySQL server, but if there is a problem, display an error telling why
?>
(submit.php)
<?php
include("dbconnect.php"
;//include the file that connects to the database
if(!empty($title)) {//if the title is not empty, than do this function
$title = addslashes($title);
$user = addslashes($user);
$message = addslashes($message);
$date = date("F j, Y"
;//set up the date format
$date2 = mktime();
$sql = "INSERT INTO mynews (id, title, user, message, date) VALUES ('NULL', '$title','$user','$message','$date')";//Insert all of your information into the mynews table in your database
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
echo "Database Updated.";
} else {//However, if the title variable is empty, than do this function
?>
<form name="news" method="post" action="<?php echo $PHP_SELF; ?>">
<p>Please fill out all of the following fields:</p>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="117"><font size="1">News Topic/Title*: </font> </td>
<td width="577">
<font size="1">
<input type="text" name="title" size="50">
</font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Username*:</font></td>
<td width="577">
<font size="1">
<input type="text" name="user" size="50">
</font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Message*:</font></td>
<td width="577">
<font size="1">
<textarea name="message" rows=10 cols=43></textarea>
</font>
</td>
</tr>
</table>
<p>
<font size="1">
<input type="submit" name="Submit" value="Submit"></font>
</p>
</form> <?php
}//end this function
?>
(viewnews.php)
<?php
include("dbconnect.php"
;//include the file to connect to the database
$getnews = mysql_query("SELECT * FROM mynews ORDER BY id DESC"
;//query the database for all of the news
while($r=mysql_fetch_array($getnews)){//while there are rows in the table
extract($r);//remove the $r so its just $variable
echo("<hr>
<font size=3>$title added on $date</font><br>
<font size=1>Posted by $user</font><br>
<font size=2>$message</font><p>"
;
}
?>
Really hope someone can help!!!
Brett