This is were I started for the code I have http://dev.mysql.com/tech-resources/art ... ws/24.html
I finally got it to work, without giving me any errors as a change some of the code because of bad syntax (since I'm a newbie it might still be bad) but anyway, is giving me no errors.
When I view my page it shows all the code to view mySQL info so I see the list of news, but when I click the Add NEWS, it refreshes and still shows the list of news but it does not show the form.
I read somewhere about SESSIONS, does this code should it be in sessions? Or I'm missing something? Anyway thanks in advanced to everyone that takes a look at this. Any other comments on coding are appreciated.
Code: Select all
<?php
// If the user wants to add a news
if (isset($addnews)) {
?>
<p>Add news to db</p>
<p>Note: News will have the date and time of post. </p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div align="left">
News Title :
<input name="news_titlev" type="text">
<br>
News:<br>
<textarea name="news_txtv" cols="40" rows="3"></textarea>
<br>
<input name="idv" type="hidden">
<input name="news_datev" type="hidden">
<br>
<input type="submit" name="action" value="Submit News">
</div>
</form>
<?PHP
} else {
$dbcnx = @mysql_connect("localhost", "****", "****");
if (!$dbcnx) {
echo( "<P>Unable to connect to the database server at this time.</P>" );
exit();
}
mysql_select_db("intranet", $dbcnx);
if (! @mysql_select_db("intranet") ) {
echo( "<P>Unable to locate the news database at this time.</P>" );
exit();
}
// If a news has been submitted, add it to the database.
if (isset($_POST['action']) && $_POST['action'] == 'submit') {
$sql = "INSERT INTO hhmnews SET news_title='$news_titlev', news_txt='$news_txtv', news_date=CURDATE()";
if (mysql_query($sql)) {
echo ("<P>Your news have been added.</P>");
} else {
echo("<P>Error adding submitted news.</P>");
}
}
echo ("<P> here are all the news in our database:</P>");
// Request the text of all the news
$result = mysql_query("SELECT * FROM hhmnews", $dbcnx);
if (!$result) {
echo("<P>Error performing query</P>");
exit();
}
if ($rows = mysql_fetch_array($result)) {
do {
printf ("<i>%s</i><br>", $rows["news_date"]);
printf ("<b>%s</b><br>", $rows["news_title"]);
printf ("%s<p>", $rows["news_txt"]);
} while ($rows = mysql_fetch_array ($result));
//if no news found
} else {
echo "<p class='text1'>No news where found at this time</p>";
}
// When clicked, this link will load this page
// with the news submission form displayed.
echo '<A HREF="'. $_SERVER['PHP_SELF'] . '?addnews=1">Add NEWS</A></P>';
}
?>