angelali
02-21-2012, 02:03 PM
I have made a simple form where users who have been subscribed and unsubscribe by inserting their email address.
In my database using PHPMyAdmin, my database to store the emails is 'Links', the table is 'email' and the fields are the 'id' and 'emailaddress'.
What I have tried is making a text input field, where the user ill insert his or her email address, to unsubscribe on the website. As a result the user's field for his or her email address will be delete in the database which is saving the emails for all users who have subscribed.
My HTML codes are:
<p>Subscribe for newsletters:</p>
<img src="images/k-newsletter-icon.png" width="96" height="96" alt="subscri"/>
<form action="index.php" method="post">
<input type="text" size="25" placeholder="Your email address..." name="enter"/>
<input class="submit" type="submit" value="Subscribe" name="subscribe"/>
</form>
My PHP codes are:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = $_POST['enter'];
@mysql_connect ('localhost', 'root', '') or die ('Error');
@mysql_select_db ('links') or die ('Error');
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Not an email";
return false;
} else {
mysql_query("DELETE FROM email WHERE emailaddress ='$email'");
echo "deleted";
}
}
?>
When I test it,it is not working, as I see the email which was saved, is still in the database! Help!
In my database using PHPMyAdmin, my database to store the emails is 'Links', the table is 'email' and the fields are the 'id' and 'emailaddress'.
What I have tried is making a text input field, where the user ill insert his or her email address, to unsubscribe on the website. As a result the user's field for his or her email address will be delete in the database which is saving the emails for all users who have subscribed.
My HTML codes are:
<p>Subscribe for newsletters:</p>
<img src="images/k-newsletter-icon.png" width="96" height="96" alt="subscri"/>
<form action="index.php" method="post">
<input type="text" size="25" placeholder="Your email address..." name="enter"/>
<input class="submit" type="submit" value="Subscribe" name="subscribe"/>
</form>
My PHP codes are:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = $_POST['enter'];
@mysql_connect ('localhost', 'root', '') or die ('Error');
@mysql_select_db ('links') or die ('Error');
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Not an email";
return false;
} else {
mysql_query("DELETE FROM email WHERE emailaddress ='$email'");
echo "deleted";
}
}
?>
When I test it,it is not working, as I see the email which was saved, is still in the database! Help!