Guest User

Untitled

a guest
Sep 6th, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. php, change a db: from MySQL to txt file
  2. require "includes/connect.php";
  3.  
  4. $msg = '';
  5.  
  6. if($_POST['email']){
  7.  
  8. // Requested with AJAX:
  9. $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
  10.  
  11. try{
  12. if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
  13. throw new Exception('Invalid Email!');
  14. }
  15.  
  16. $mysqli->query("INSERT INTO coming_soon_emails
  17. SET email='".$mysqli->real_escape_string($_POST['email'])."'");
  18.  
  19. if($mysqli->affected_rows != 1){
  20. throw new Exception('This email already exists in the database.');
  21. }
  22.  
  23. if($ajax){
  24. die('{"status":1}');
  25. }
  26.  
  27. $msg = "Thank you!";
  28.  
  29. }
  30. catch (Exception $e){
  31.  
  32. if($ajax){
  33. die(json_encode(array('error'=>$e->getMessage())));
  34. }
  35.  
  36. $msg = $e->getMessage();
  37. }
  38. }
  39.  
  40. <?php
  41.  
  42. error_reporting(E_ALL ^ E_NOTICE);
  43.  
  44. $db_host = '';
  45. $db_user = '';
  46. $db_pass = '';
  47. $db_name = '';
  48.  
  49. @$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
  50.  
  51. if (mysqli_connect_errno()) {
  52. die('<h1>Could not connect to the database</h1><h2>Please try again after a few moments.</h2>');
  53. }
  54.  
  55. $mysqli->set_charset("utf8");
  56.  
  57.  
  58. ?>
  59.  
  60. $file = fopen('path/to/file', 'r+');
  61.  
  62. fputs($file, 'email@domain.com');
  63. // fputs() is an alias for fwrite, they are interchangable
Add Comment
Please, Sign In to add comment