Jump to content

Only allow email addresses to be submitted


dachshund

Recommended Posts

Hi there,

 

I have a newsletter sign up form which just puts the data (id and email) into a mysql table.

 

To stop people hacking the site, is there a way to make sure the only thing being submitted in the input is an email address?

 

Here's my current form and submit php:

 

<?php

$mailer = $_GET['mailer'];

if ($mailer == 'added')	{

$email=$_POST['email'];

if($email == '')	{
echo '<div class="daily_not_submitted"><span style="padding-right:6px;"><img src="https://store.huhmagazine.co.uk/images/cross.jpg"></span>Please fill in all the fields.</div>';
}else	{

$sql="INSERT INTO `dailymailer` (`email`) VALUES ('$email');";
$result=mysql_query($sql) or die(mysql_error());

if($result){
echo "<div class='daily_submitted'><span style='padding-right:6px;'><img src='http://www.huhmagazine.co.uk/images/uploaded/checkboxtick.jpg'></span>Thank you.</div>";
}
else {
echo "Error\n";
}
}
}
?>

<div id="sidebarnewsletter">
	<form name="mailinglist" method="post" action="?mailer=added">
		<input type="text" name="email" class="sidebarnewsletter" placeholder="Enter Your Email Address" />
		<input type="submit" class="sidebarnewsletter_button" value="Sign Up">
	</form>
	<div class="clear"></div>
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.