basically iam doing a simple news posting system, i did previously do one where the news articles are saved into a file and then read+formatted.
now i want to use a database.
i put a test story on the database and wrote the script to display the news table on the database, this works fine but its the posting iam having problems with.
i post the news in the form - it then says posted and takes me to the page were the news is but theres no news and i cant really understand why
addnews.php
PHP Code:
<?php
if (!$_POST['submit'])
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Title<input size="50" maxlength="250" type="text" name="title">
<br>
Contact info
<input size="50" maxlength="250" type="text" name="contact">
</p>
<p>Story <br>
<textarea name="content" cols="40" rows="10"></textarea>
<br>
<input type="submit" name="submit" value="Add">
</p>
</form>
<?php
}
else
{
$title = $_POST['title'];
$content = $_POST['content'];
$contact = $_POST['contact'];
include ('database_details.php');
$query = "INSERT INTO news(title, content, contact, timestamp) VALUES('$title', '$content', '$contact', NOW())";
echo 'News added <a href=news.php>Click here to see your message</a>';
mysql_close($connect);
}
?>
database_details.php
PHP Code:
<?php
$connect = mysql_connect('host', 'username', 'passy') or die ('No connection could be made');
mysql_select_db('database') or die ('unable to find database');
?>
iam not sure if there is an error in the code or its my dodgy hosting playing up
wont have to put up with that crap hosting for much longer though