Advertisement
firoze

Set A Comment system by my own php code

Oct 6th, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. // Set A Comment system by my own php code
  2.  
  3.  
  4. <div class="container text-left">
  5. <div class="row">
  6. <div class="col-md-6">
  7. <?php
  8.  
  9. $con = mysql_connect('localhost','root','');
  10. if(!$con){
  11. die('connection codivdn\'t be created'.mysql_error());
  12. }
  13.  
  14.  
  15. // create database
  16. if( mysql_query('CREATE DATABASE messagedata',$con) ){
  17. echo 'database has been created<br>';
  18. }
  19. else{
  20. // echo 'database couldn\'t be created OR Database Already Created<br>';
  21. }
  22.  
  23.  
  24. // create table
  25. mysql_select_db('messagedata',$con);
  26. $table = 'CREATE TABLE messageinfo
  27. (
  28. name varchar (50),
  29. email varchar (50),
  30. comment varchar (1800)
  31. )
  32. ';
  33. if(mysql_query($table,$con)){
  34. // echo 'Table Has Been Created<br>';
  35. }
  36.  
  37.  
  38. // Data Preview
  39. mysql_select_db("messagedata",$con);
  40.  
  41. $output = mysql_query ("SELECT * FROM messageinfo");
  42.  
  43. $image = get_template_directory_uri();
  44.  
  45. while($row = mysql_fetch_array ($output))
  46. {
  47. echo "<div style='color:#000;border:1px solid red;margin-bottom:5px;padding:15px;border-left:15px solid #4CB848;border-right:15px solid #4CB848;background:url($image/images/bg4.jpg') scroll 0px 0px'>";
  48. echo '<div><p>'.'Name : '.$row['name'].'</p></div>';
  49. echo '<div><p>'.'Email : '.$row['email'].'</p></div>';
  50. echo '<div><p>'.'Comments : '.$row['comment'].'</p></div>';
  51. echo '</div>';
  52.  
  53. }
  54. echo "</div>";
  55.  
  56. if(isset($_REQUEST['st_submit'])){
  57. $st_name = $_REQUEST['st_name'];
  58. $st_email = $_REQUEST['st_email'];
  59. $st_msg = $_REQUEST['st_msg'];
  60. if( ($st_name == true) && ($st_email == true) && ($st_msg == true) ){
  61.  
  62. mysql_select_db('messagedata',$con);
  63. if(mysql_query("INSERT INTO messageinfo (name,email,comment) VALUE ('$st_name','$st_email','$st_msg')")){
  64. echo 'Data has been included';
  65. }
  66.  
  67. }
  68. else{
  69. echo '<span style="color:red">Fill Up All Form Correctly</span> ';
  70. }
  71. }
  72.  
  73.  
  74. echo '<form action="" method="post">
  75. <table>
  76. <tr>
  77. <td>Name:</td>
  78. <td><input type="text" name="st_name" placeholder="Name" /></td>
  79. </tr>
  80. <tr>
  81. <td>Email:</td>
  82. <td><input type="email" name="st_email" placeholder="Email" /></td>
  83. </tr>
  84. <tr>
  85. <td>Comments:</td>
  86. <td><textarea style="width:335px;height:150px" type="text" name="st_msg" placeholder="Comments"></textarea></td>
  87. </tr>
  88. <tr>
  89. <td></td>
  90. <td><input type="submit" name="st_submit" value="Submit" /></td>
  91. </tr>
  92. </table>
  93. </form>';
  94.  
  95. mysql_close($con);
  96.  
  97.  
  98. ?>
  99.  
  100. <style type="text/css">
  101. td h2{padding:0 15px;margin:5px 0;font-size:15px;}
  102. input,textarea{padding-left:5px;}
  103. </style>
  104.  
  105. </div>
  106. </div>
  107. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement