Argh! You're looping through every single row in the database!
The solution is to redesign your database (and remove this gods-awful code!). It should look something like this (MySQL):
Code:
CREATE TABLE subscribers (id INT AUTO_INCREMENT, email VARCHAR(320), UNIQUE(email), PRIMARY KEY(id));
Then, that hideous mess above becomes:
Code:
mysql_select_db('bristoldnb_mail', $con);
if (!mysql_query(sprintf('INSERT INTO subscribers (email) VALUES (\'%s\')', mysql_real_escape_string($email))))
if (mysql_errno() === 1062) // ER_DUP_ENTRY
die(header("Location: ${server_url}php/index.php?pass=taken"));
else
die(mysql_error());
Or, preferably, using PDO if your server supports it (this code also includes the equivalent of your mysql_connect() call [with variables $hostname, $username, $password]):
Code:
$db = new PDO("mysql:host=$hostname;dbname=bristoldnb_mail", $username, $password);
try {
$st = $db->prepare('INSERT INTO subscribers (email) VALUES (:email)');
$st->bindParam(':email', $email);
$st->execute();
} catch (PDOException $e) {
if ($e->getCode() === 1062) // ER_DUP_ENTRY
die(header("Location: ${server_url}php/index.php?pass=taken"));
else
die($e->getMessage());
}
Bookmarks