PHP Blog: Insert.php


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. //mysql database connection
  4. $dbhost='Database Host';
  5. $dbuser='Your Username';
  6. $dbpass='Your Password';
  7. $dbtable='Your Table Name';
  8.  
  9. mysql_connect("$dbhost", "$dbuser", "$dbpass") or die("Could not connect.");
  10. mysql_select_db("$dbtable") or die("Table could not be selected.");
  11.  
  12. //Submit Form
  13. if(isset($_POST['submit']))
  14. {
  15. $yourpost=$_POST['yourpost'];
  16.  
  17. if(strlen($yourpost)<1)
  18. {
  19. print "You did not enter a message."; //no post entered
  20.  
  21. }else{
  22.  
  23. $displaytime=date("F j, Y, g:i A");
  24.  
  25. //SQL Queries
  26. $insertpost="INSERT INTO kyproject_blog(message, date) values('$yourpost','$displaytime')";
  27. mysql_query($insertpost) or die("Could not insert post"); //insert post
  28. print "Blog entry added. Return to the <a href='index.php'>index page</a>.";
  29. }
  30.  
  31. }else{
  32.  
  33. print "<fieldset>
  34. <form action='' method='post' id='ticketform'>
  35. <p><label>Blog Entry:</label>
  36. <textarea cols='50' rows='11' name='yourpost' id='message' class='bbeditor'></textarea></p>
  37. <p><input name='submit' class='formbutton' value='Submit' type='submit' /></p>
  38. </form>";
  39. }
  40. print "</td></tr></tbody></table>
  41. </fieldset>";
  42. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.