I get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/racingri/public_html/emails/index.php on line 49
Here's index.php:
<?php
define('TINYAJAX_PATH', './include');
require_once(TINYAJAX_PATH . '/TinyAjax.php');
require_once(TINYAJAX_PATH . '/db.php');
function IsValidEmail($email) {
$atom_re = "[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+";
$regexp = "/^(" . $atom_re . ")(\\." . $atom_re .
")*@([a-z0-9-]+)(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$/i";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (preg_match($regexp, $email)) {
if (function_exists("getmxrr")) {
list($username, $domaintld) = split("@", $email);
while (substr_count($domaintld, ".") > 0) {
// Validate the domain
if (getmxrr($domaintld, $mxrecords)) {
$valid = 1;
break;
}
// Didn't find an MX record.
// If we have a subdomain, move up the hierarchy.
list($dummy, $domaintld) = split(".", $domaintld, 2);
}
} else {
// Couldn't check the domain with getmxrr, assume the best.
$valid = 1;
}
}
return $valid;
}
//Submit function
function submitemailaddy($email) {
if (IsValidEmail($email) == 0) {
$result = '<strong>Sorry, your email address appears to be invalid. </strong>';
} else {
$sql_email_check = mysql_query("SELECT * FROM email WHERE emailaddress='$emailaddress'");
$email_check = mysql_num_rows($sql_email_check);
if ($email_check == 0) {
$sql = mysql_query("INSERT INTO email (emailaddress) VALUES('$email') ") or die (mysql_error());
$result = '<strong>Email Added.</strong>';
} else {
$result = '<strong>Email address already in database.</strong>';
}
}
return $result;
}
//Post
if(!empty($_POST['email'])) {
$email = $_POST['email'];
$result = submitemailaddy($email);
}
//Ajax
$ajax = new TinyAjax();
$ajax->exportFunction("submitemailaddy", array("email"), "#result");
$ajax->showLoading(); // Show loading while callback is in progress
$ajax->process();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Emails</title>
<? $ajax->drawJavaScript(false, true); ?>
<style type="text/css">
<!--
p {
border: 1px dotted #A32A22;
width: 500px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</head>
<body>
<div>
<div align="center">
<form method="post" action="">
<p id="result">
<?php
if (empty($result)) {
echo '<strong>To pre-register, please enter your email address below:</strong><br />
Email:
<input type="text" name="email" />
<input type="submit" name="Submit" value="Register" onclick="return submitemailaddy();" />
';
} else {
echo $result;
echo '<strong>To pre-register, please enter your email address below:</strong><br />
Email:
<input type="text" name="email" />
<input type="submit" name="Submit" value="Register" onclick="return submitemailaddy();" />
';
}
?>
<?php
$membercount = mysql_query("SELECT * FROM email");
?>
</p>
<p>There are currently <?=mysql_num_rows($membercount);?> email addresses in the database.</p>
</form>
</div>
</div>
</body>
</html>
<?php
//#######################################################################\\
// This script is freeware.
// Programed by Simon Keung.
//########################### -END OF FILE- #############################\\
?>
Anyone know why? I think it's a database problem... so here's the SQL in the database:
CREATE TABLE `email` (
`emailid` int(15) NOT NULL auto_increment,
`emaladdress` varchar(1000) NOT NULL,
PRIMARY KEY (`emailid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Thanks! 🙂