Jump to content

News Page Error


krustykobb

Recommended Posts

Hi,
 
I am writing some code for a news page for a website I am developing, and I get the following error:
 

 

Notice: Undefined index: body in C:\xampp\htdocs\post.php on line 12
 
The code I am working with is:
 
<html> <h1>Post News</h1><hr> <?php if (isset($_POST['post'])){//get data$title = $_POST['title'];$body = $_POST['body']; //check for existance if ($title&&$body){//insert data mysql_connect ("localhost","root","test1234","") or die (mysql_error ());mysql_select_db("beavers") or die (mysql_error());  $date = date ("d-m-Y");$insert = mysql_query("insert INTO news VALUES '','$title','$body','$date')") or die (mysql_error()) ; die("Your news has been posted");}elseecho "Please fill out title and body<p>";}       ?> <form action='post.php' method='POST'>Title:<br>        <input type='text' name='title'><p> Body:<br>        <textarea rows='6' cols='35 name='body'></textarea><p>                <input type='submit' name='post' value='Post this news'/> </form>   <hr></html>

 
And the actual news page is:
 
<html><h1>News</h1><hr> <?php //connect mysql_connect ("localhost","root","test1234","") or die (mysql_error ());mysql_select_db("beavers") or die (mysql_error());   //query database $getnews = mysql_query("SELECT * FROM news") or die (mysql_query); while ($row = mysql_fetch_assoc ($getnews)){ //get data$id = $row['id'];$title = $row['title'];$body = $row['body'];$date = $row['date'];   echo "<b>$title posted on $date</b><br>"; echo nl2br ($body); echo"<hr>"; } ?>      </html>

 
Any help is greatly appreciated.
Link to comment
https://forums.phpfreaks.com/topic/281074-news-page-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.