Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- news.php
- <html>
- <h1>News</h1>
- <hr>
- <?php
- // connect
- mysql_connect("localhost","root","") or die(mysql_error());
- mysql_select_db("newssystem") or die(mysql_error());
- //query the db
- $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<b> posted on <i>$date</i><br>
- ";
- echo nl2br($body);
- echo "<hr>
- ";
- }
- ?>
- <hr>
- </html>
- post.php
- <html>
- <h1>Post news</h1>
- <hr>
- <?php
- if ($_POST['post'])
- {
- //get data
- $title = $_POST['title'];
- $body = $_POST['body'];
- // check for existance
- if ($title&&$body)
- {
- // connect
- mysql_connect("localhost","root","") or die(mysql_error());
- mysql_select_db("newssystem") or die(mysql_error());
- $date = date("Y-m-d");
- //insert data
- $insert = mysql_query("INSERT INTO news VALUES('','$title','$body','$date')") or die(mysql_error());
- die("The news has been posted.");
- }
- else
- echo "Please fill out title and body.";
- }
- ?>
- <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 News'>
- <hr
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement