Aug 25th, 2009, 7:58 PM
I'm trying to utilize the ft_api_check_submission_is_unique feature in conjunction with validation and the result is the following error:
The validation is working just fine... but once past that it brings up this error (regardless of whether the entry is unique or not)... and it also displays the text saying it's not unique -- even if it is.
You can see it in play at: http://fasports.com/test/test.php
...and the full page code:
Any help is greatly appreciated! Thanks!
Code:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /[directory]/global/api/api.php on line 1523
The validation is working just fine... but once past that it brings up this error (regardless of whether the entry is unique or not)... and it also displays the text saying it's not unique -- even if it is.
You can see it in play at: http://fasports.com/test/test.php
...and the full page code:
Code:
<?php
require_once("../[directory]/global/api/api.php");
$fields = ft_api_init_form_page(28);
$already_exists = "";
// validation time!
$errors = array();
if (isset($_POST['submit']))
{
$rules = array();
$rules[] = "required,how_they_heard_about_us,Please select a referral source.";
$rules[] = "required,email,Please enter your email address.";
$errors = validate_fields($_POST, $rules);
// no errors - great! Now we process the page. The ft_api_process_form does
// the job of both updating the database and redirecting to the next page
if (empty($errors))
{
$params = array(
"submit_button" => "submit",
"next_page" => "thanks.php",
"form_data" => $_POST,
"finalize" => true
);
$criteria = array(
"email" => $_POST["email"]
);
if (ft_api_check_submission_is_unique(28, $criteria))
{
// uh-oh! A submission already exists with this email address! Abort, abort!
// here, you could do something like set a variable like: $already_exists = true
// and in the webpage do a little test to see if it's set. If so, let the user know
// what's going on
$already_exists = true;
}
else
{
// call ft_api_process_form function here to continue processing the form submission
ft_api_process_form($params);
}
}
}
?>
<html>
<head>
</head>
<body>
<? if($already_exists == true) { echo("**This email already exists**<br/><br/>"); } ?>
<?php
// if $errors is not empty, the form must have failed one or more validation
// tests. Loop through each and display them on the page for the user
if (!empty($errors))
{
echo "<div class='error'>Please fix the following errors:\n<ul>";
foreach ($errors as $error)
echo "<li>$error</li>\n";
echo "</ul></div>";
}
?>
Join our mailing list for league and tournament updates:
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
<input type="text" name="email" size="30" value="<?=htmlspecialchars(@$fields["email"])?>">
<select name="how_they_heard_about_us">
<option value="">Your Referral Source</option>
<option value="MySpace">MySpace</option>
<option value="Facebook">Facebook</option>
<option value="Search Engine">Search Engine</option>
<option value="Friend">Friend</option>
<option value="Advertisement">Advertisement</option>
<option value="Other">Other</option>
</select>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Any help is greatly appreciated! Thanks!