Schmoopy
01-16-2009, 10:46 PM
Ok so I'm still trying to code a newsletter system, and am at the registration stage, and am trying to achieve the following:
Validate user id and hash.
Check email is not already active.
Update table if details are correct.
At the moment, when the user first signs up to the newsletter, their details are stored in a table with the following fields : ID, email and Active.
When the user first signs up the Active field is 0 by default, and an email is sent out to their account to verify they want to join.
Here is the code I'm currently using (and yes it's probably terrible, but there you go...):
<?php
$title = "Bristol DNB - Register";
include("page_header.php");
$hash = $_GET['ver'];
$id = $_GET['id'];
if ($id == "" || $hash == "")
{
die("Invalid information");
}
$con = @mysql_connect("$host","$user","$password");
mysql_select_db("bristoldnb_mail",$con);
if (!$con)
{
die("Looks like something went wrong while connecting to the server, please try again later<p></p>You will be redirected back to the home page in 10 seconds, or click <a href=\"$server_url\">here</a>");
}
$active = mysql_query("SELECT `email` FROM `subscribers` WHERE `ID` = '$id' AND `Active` = '1'");
if($srow = mysql_fetch_row($active))
{
die("Subscription already active");
}
elseif($sql = mysql_query("SELECT `email` FROM `subscribers` WHERE `ID` = '$id' AND `Active` = '0'")) {
if (mysql_fetch_row($sql))
{
die("Oh noes");
}
$row = mysql_fetch_row($sql);
$email = $row[0];
if ($hash == sha1($email . "bristoldnb"));
{
mysql_query("UPDATE `subscribers` SET `Active` = '1' WHERE `id` = '$id'");
echo "Registration Successul";
}
}
?>
</div>
<div id="content">
<div id="unsubscribe">
</div>
</div>
<?php
include("page_footer.php");
?>
I'm pretty sure some of the code doesn't make sense but I've just been playing around with values to get some sort of response from the php.
Sort of lost as to what to do, I've tried using invalid ids and hash keys but still not working.
Thanks for any help,
Jack.
Validate user id and hash.
Check email is not already active.
Update table if details are correct.
At the moment, when the user first signs up to the newsletter, their details are stored in a table with the following fields : ID, email and Active.
When the user first signs up the Active field is 0 by default, and an email is sent out to their account to verify they want to join.
Here is the code I'm currently using (and yes it's probably terrible, but there you go...):
<?php
$title = "Bristol DNB - Register";
include("page_header.php");
$hash = $_GET['ver'];
$id = $_GET['id'];
if ($id == "" || $hash == "")
{
die("Invalid information");
}
$con = @mysql_connect("$host","$user","$password");
mysql_select_db("bristoldnb_mail",$con);
if (!$con)
{
die("Looks like something went wrong while connecting to the server, please try again later<p></p>You will be redirected back to the home page in 10 seconds, or click <a href=\"$server_url\">here</a>");
}
$active = mysql_query("SELECT `email` FROM `subscribers` WHERE `ID` = '$id' AND `Active` = '1'");
if($srow = mysql_fetch_row($active))
{
die("Subscription already active");
}
elseif($sql = mysql_query("SELECT `email` FROM `subscribers` WHERE `ID` = '$id' AND `Active` = '0'")) {
if (mysql_fetch_row($sql))
{
die("Oh noes");
}
$row = mysql_fetch_row($sql);
$email = $row[0];
if ($hash == sha1($email . "bristoldnb"));
{
mysql_query("UPDATE `subscribers` SET `Active` = '1' WHERE `id` = '$id'");
echo "Registration Successul";
}
}
?>
</div>
<div id="content">
<div id="unsubscribe">
</div>
</div>
<?php
include("page_footer.php");
?>
I'm pretty sure some of the code doesn't make sense but I've just been playing around with values to get some sort of response from the php.
Sort of lost as to what to do, I've tried using invalid ids and hash keys but still not working.
Thanks for any help,
Jack.