PDA

View Full Version : Info Verification Problem


nisim7
10-31-2006, 07:22 AM
I cannot figure out what is wrong with my code here. The email verification works properly (checking if it is a valid email address format). The check for existing information works, but if the row is empty, it will not insert the new address. Here is the code:

if (!preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i', trim($_GET['email']))) {
echo "<h4>Sorry</h4><br /> This email address is invalid, please try again</div>";

} else {

include('config.php');
$email = addslashes($_GET['email']);
$query1 = mysql_query("SELECT * FROM subscribers WHERE email = '$email'");
$result1 = mysql_num_rows($query1) or die(mysql_error());

if ($result1 !== "0") {
echo "<h4>We're Sorry</h4><br /> That e-mail address is already being used.";

} else {

echo "<h4>Congratulations!</h4>
You have subscribed to Afterburn SF! We will send you an e-mail when the next publication is released containing links to the stories in that issue.";

$query = "INSERT INTO subscribers VALUES ('$email')";
$result = mysql_query($query, $conn) or die(mysql_error());
}
}

darksidepuffin
10-31-2006, 07:28 AM
Try using != rather than !== -- !== is a completely different operator -- oh..and try changing your insert to:

INSERT INTO subscribers (email) VALUES ('$email')

nisim7
10-31-2006, 07:36 AM
thanks for the help. i made the changes, but it is still not working. I get a blank div when I try to put in a new email address. It's not that it is just not updating the database, I don't even get the echoed text. I'm pretty sure that I'm not missing a closing bracket or semi-colon.

Gamini
10-31-2006, 08:09 AM
I ran a syntax check on the php file and it turned up squeaky clean.

i suggest you place echo statements along the way to see where the script is halting, if nothing is working then check if the script is being run properly, upload a test script and see if that runs.

Hope one of these work.

Cheers :)

nisim7
10-31-2006, 08:48 AM
From what I can tell, it is breaking after the second (nested) else statement. Nothing after that works. the nested if statement works, but it is as if it is saying "there is a $result1 != "0", but there is no $result1 == "0""

The script totally breaks at that point

darksidepuffin
10-31-2006, 08:56 AM
Try just doing if($result1 > 0) -- also..echo out what $result1 actually equals.

nisim7
10-31-2006, 09:32 AM
I am absolutely baffled. I have tried everything that you all have suggested, and am still getting the hang up after the end of the if statement. Here is the entire page code, rather than just the snippet:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!--
XHTML 1.0 Transitional
Document type as defined on http://www.w3.org/TR/xhtml1/
-->
<head>
<meta http-equiv="Content-Language" content="en" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<title>Afterburn SF - The Very Best in Speculative Fiction</title>
</head>

<body>

<!-- Site Header -->
<div id="header">
<?php include("header.php"); ?>
</div> <!-- End site header div -->

<div id="main1"> <!-- Begin Main1 div -->

<!-- Left Nav -->
<div id="left">
<?php include("leftnav.php"); ?>
</div> <!-- End Left Nav div -->

<!-- Rigth Nav -->
<div id="right">
<?php include("rightnav.php"); ?>
</div> <!-- End Right Nav div -->

<?php


echo "
<div id='middle'> <!-- Begin middle div -->
<div id='middlecontent'> <!-- Begin middle content div -->";

if (!preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i', trim($_GET['email']))) {
echo "<h4>Sorry</h4><br /> This email address is invalid, please try again</div>";

} else {

include('config.php');
$email = addslashes($_GET['email']);
$query1 = mysql_query("SELECT * FROM subscribers WHERE email = '$email'");
$result1 = mysql_num_rows($query1) or die(mysql_error());

if ($result1 > 0) {
echo "<h4>We're Sorry</h4><br /> That e-mail address is already being used.";

} else {
echo "<h4>Congratulations!</h4>
You have subscribed to Afterburn SF! We will send you an e-mail when the next publication is released containing links to the stories in that issue.";

$query = "INSERT INTO subscribers (email) VALUES ('$email')";
$result = mysql_query($query, $conn) or die(mysql_error());
}
}

echo "</div>
</div>";

?>
</div>
<?php include("footer.php"); ?>

</body>
</html>