PHP Blog: Insert2.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. $blogid=$_POST['blogid'];
  17.  
  18. if(strlen($yourpost)<1)
  19. {
  20. print "You did not enter a message."; //no message entered
  21. }
  22. elseif($blogid != '') {
  23. $qry = "SELECT * FROM kyproject_blog WHERE blogid='$blogid'";
  24. $result = mysql_query($qry);
  25. if($result) {
  26. if(mysql_num_rows($result) > 0) {
  27.  
  28. echo 'Blog ID is already in use.';
  29. }
  30. @mysql_free_result($result);
  31. }
  32. else {
  33. die("Query failed");
  34. }
  35. }else{
  36.  
  37. $displaytime=date("F j, Y, g:i A");
  38.  
  39. //SQL Queries
  40. $insertpost="INSERT INTO kyproject_blog(blogid, message, date) values('$blogid','$yourpost','$displaytime')";
  41. mysql_query($insertpost) or die("Could not insert post"); //insert post
  42. print "Blog entry added. View it <a href='blog.php?id=$blogid'>here</a>.";
  43. }
  44.  
  45. }else{
  46.  
  47. print "<fieldset>
  48. <form action='' method='post' id='ticketform'>
  49. <p><label>Blog ID(Identifier Name):</label>
  50. <input name='blogid' id='textarea' type='text' /></p>
  51. <p><label>Blog Entry:</label>
  52. <textarea cols='50' rows='11' name='yourpost' id='message' class='bbeditor'></textarea></p>
  53. <p><input name='submit' class='formbutton' value='Submit' type='submit' /></p>
  54. </form>";
  55. }
  56. print "</td></tr></tbody></table>
  57. </fieldset>";
  58. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.