It doesn't like mysql_num_rows. I changed the code and added some comments so I don't get lost. The error I'm getting is:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
Here's the updated code. It's throwing the error below where I commented - // See if any results were returned
<?php require_once('Connections/connAddresses.php'); ?>
<?php
// Get the value - the email address from the form
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
// Create query to check DB for email address
$result = mysql_query("SELECT address FROM table_addresses WHERE address = '$theValue'");
// See if any results were returned
$num_rows = mysql_num_rows($result);
// if email is not in DB add the email to the DB and go to process.php
if ($num_rows = 0)
{
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "address_form")) {
$insertSQL = sprintf("INSERT INTO table_addresses (address) VALUES (%s)",
GetSQLValueString($HTTP_POST_VARS['address_field'], "text"));
mysql_select_db($database_connAddresses, $connAddresses);
$Result1 = mysql_query($insertSQL, $connAddresses) or die(mysql_error());
$insertGoTo = "process.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
// if email IS already in DB just go to process.php
if ($result > 0)
header("Location:process.php");
}
?>