Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- php, change a db: from MySQL to txt file
- require "includes/connect.php";
- $msg = '';
- if($_POST['email']){
- // Requested with AJAX:
- $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
- try{
- if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
- throw new Exception('Invalid Email!');
- }
- $mysqli->query("INSERT INTO coming_soon_emails
- SET email='".$mysqli->real_escape_string($_POST['email'])."'");
- if($mysqli->affected_rows != 1){
- throw new Exception('This email already exists in the database.');
- }
- if($ajax){
- die('{"status":1}');
- }
- $msg = "Thank you!";
- }
- catch (Exception $e){
- if($ajax){
- die(json_encode(array('error'=>$e->getMessage())));
- }
- $msg = $e->getMessage();
- }
- }
- <?php
- error_reporting(E_ALL ^ E_NOTICE);
- $db_host = '';
- $db_user = '';
- $db_pass = '';
- $db_name = '';
- @$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
- if (mysqli_connect_errno()) {
- die('<h1>Could not connect to the database</h1><h2>Please try again after a few moments.</h2>');
- }
- $mysqli->set_charset("utf8");
- ?>
- $file = fopen('path/to/file', 'r+');
- fputs($file, 'email@domain.com');
- // fputs() is an alias for fwrite, they are interchangable
Add Comment
Please, Sign In to add comment