Advertisement
eladha

stop insert after refresh page

Dec 13th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. // منع ارسال البيانات بعد عمل تحديث للصفحة
  2.  
  3. <?php
  4. error_reporting(0);
  5. $localhost="localhost";
  6. $db_user="root";
  7. $db_password="";
  8. $db_name="insert";
  9.  
  10. $connect_db = mysql_connect($localhost,$db_user,$db_password);
  11. mysql_select_db($db_name);
  12.  
  13. /*
  14.  CREATE TABLE  `news`.`addnews` (
  15. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  16. `author` VARCHAR( 225 ) NOT NULL ,
  17. `title` VARCHAR( 225 ) NOT NULL ,
  18. `title` LONGTEXT NOT NULL
  19. ) ENGINE = MYISAM ;
  20.  */
  21.  
  22. if(isset($_POST['submit'])){
  23.     $n =$_POST['name'];
  24.     $t =$_POST['title'];
  25.     $c =$_POST['content'];
  26.  
  27.     if(empty($n) or empty($t) or empty($c)){
  28.         echo'<h3>Please insert all input and click Insert</h3>';
  29.         echo'<meta http-equiv="refresh" content="3;url=insert_2.php"/>';
  30.     }else{
  31.         $q = mysql_query("insert into addnews (author,title,content) values ('$n','$t','$c')")
  32.         or die (" insert not ");
  33.         header('Location: insert_2.php');
  34.         exit;
  35.     }
  36. }
  37.  
  38. echo "
  39. <form action='".$SERVER['PHP_SELF']."' method='post'>
  40.    <p> Name : <input type='text' name='name'/> </p>
  41.    <p>Title : <input type='text' name='title'/> </p>
  42.    <p>Content</p> <br/>
  43.    <textarea name='content' rows='8' cols='40'> </textarea>  <br/>
  44.    <p> <input type='submit' name='submit' value='Insert'> </p>
  45.    <input type='hidden' name='add' value='news' />
  46. </form>
  47. ";
  48. mysql_close($connect_db);
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement