Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP/html email form no longer submitting to mysql database
- <form method="post" action="process-form.php" id="emailForm" name="emailForm" target="_self">
- <h4>Sign up to be notified when we go live!</h4>
- <label for="email">E-mail</label>
- <input type="text" name="email" id="email" />
- <input type="submit" name="submit" id="submit" value="Submit" onclick="return alert('Thanks! Your email has been added.');">
- <p>emails will not be shared with third parties</p>
- </form>
- <?php
- //open database connect
- $username = "username";
- $password = "password";
- $hostname = "server";
- $conn = mysql_connect($hostname, $username, $password);
- if (!$conn) die('Could not connect: ' . mysql_error());
- //emaillist is the name of the database
- mysql_select_db('emaillist');
- //Clean data
- function clean_data($string){
- if (get_magic_quotes_gpc()){
- $string = stripslashes($string);
- }
- $string = strip_tags($string);
- return mysql_real_escape_string($string);
- }
- //Mail Header removal
- function remove_headers($string){
- $headers = array(
- "/to:/i",
- "/from:/i",
- "/bcc:/i",
- "/cc:/i",
- "/Content-Transfer-Encoding:/i",
- "/Content-Type:/i",
- "/Mime-Version:/i",
- );
- $string = preg_replace($headers, '', $string);
- return strip_tags($string);
- }
- //Pick up cleaned data
- $email = clean_data($_POST['email']);
- //Insert data
- //emails is the name of the table
- $query ="INSERT INTO emails (email)
- VALUES ('$email')";
- mysql_query($query);
- //close Connection
- mysql_close($conn);
- //redirect to page
- header('Location: defaultUpCyc.html');
- ?>
- if (!$conn) { die('Could not connect: ' . mysql_error()); }
Add Comment
Please, Sign In to add comment