could you help me with that? I know nothing about SQL and so little aboot php.You should have variables on top regarding you should also have a $query variable that will request data to your database so just do mysql_num_rows($query) if they query is used again the data will not insert to database.
<?php
mysql_connect( "localhost", "user", "pass" ) or die( mysql_error() );
mysql_select_db( "dbname" ) or die( mysql_error() );
if ( isset( $_POST["submit"] ) )
{
$email = strip_tags( $_POST["email"] );
$error = array();
if ( empty( $error ) ) $error[] = 'Please enter an email address.';
if ( !filter_var( $email, FILTER_VALIDATE_EMAIL ) ) $error[] = 'Please enter a valid email address.';
if ( mysql_num_rows( mysql_query( "SELECT * FROM `EmailTable` WHERE `EmailAddress` = '" . mysql_real_escape_string( addslashes( $email ) ) . "'" ) ) > 0 ) $error[] = 'This email address has already been used.';
if ( !empty( $error ) )
{
echo '<ul>';
foreach ( $error as $v ) { echo '<li>' . $v . '</li>'; }
echo '</ul>';
}
else
{
@mysql_query( "INSERT INTO `EmailTable` (`EmailAddress`, `IPAddress`) VALUES ('" . $email . "', '" . $_SERVER['REMOTE_ADDR'] . "')" );
mail( "[email protected]", "subject", "message", "From: {$email}" );
}
}
else
{
echo '<form method="post" action="' . $_SERVER["PHP_SELF"] . '">
<label for="email">Email Address:</label> <input type="text" name="email" id="email" value="" /><br />
<input type="submit" name="submit" value="Go" />
</form>';
}
?>
Thanks!You can set the database up yourself, but I'll start you off on a little checking system.
It should work, I coded it in the post box here. As I said, create the database yourself and change the MySQL details and table/column details.
PHP:<?php mysql_connect( "localhost", "user", "pass" ) or die( mysql_error() ); mysql_select_db( "dbname" ) or die( mysql_error() ); if ( isset( $_POST["submit"] ) ) { $email = strip_tags( $_POST["email"] ); $error = array(); if ( empty( $error ) ) $error[] = 'Please enter an email address.'; if ( !filter_var( $email, FILTER_VALIDATE_EMAIL ) ) $error[] = 'Please enter a valid email address.'; if ( mysql_num_rows( mysql_query( "SELECT * FROM `EmailTable` WHERE `EmailAddress` = '" . mysql_real_escape_string( addslashes( $email ) ) . "'" ) ) > 0 ) $error[] = 'This email address has already been used.'; if ( !empty( $error ) ) { echo '<ul>'; foreach ( $error as $v ) { echo '<li>' . $v . '</li>'; } echo '</ul>'; } else { mail( "[email protected]", "subject", "message", "From: {$email}" ); } } else { echo '<form method="post" action="' . $_SERVER["PHP_SELF"] . '"> <label for="email">Email Address:</label> <input type="text" name="email" id="email" value="" /><br /> <input type="submit" name="submit" value="Go" /> </form>'; } ?>
Edited my previous post. I forgot to add the code to insert the email into the database once it has been sent.Thanks!