The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1370 fetch_forum_permissions
/printthread.php 76 forum_permissions
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(257) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/printthread.php(257) : eval()'d code 2 errorHandler->error
/printthread.php 257 eval
/printthread.php 117 printthread_multipage
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
SQL error when using ft_api_check_submission_is_unique - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1)
+--- Forum: API (https://forums.formtools.org/forumdisplay.php?fid=17)
+--- Thread: SQL error when using ft_api_check_submission_is_unique (/showthread.php?tid=264)

Pages: 1 2


SQL error when using ft_api_check_submission_is_unique - msaz87 - Aug 25th, 2009

I'm trying to utilize the ft_api_check_submission_is_unique feature in conjunction with validation and the result is the following error:

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>&nbsp;
    <input type="submit" name="submit" value="submit">

</form>

</body>
</html>

Any help is greatly appreciated! Thanks!


RE: SQL error when using ft_api_check_submission_is_unique - Ben - Sep 1st, 2009

Heya,

Sorry for the wait - hectic week!

I just took a look at it and I don't get that error myself. Also, there's no mysql_fetch_assoc function on that line. What version of the API are you running? (You can find out by looking at the top of the api.php file, or logging into Form Tools and going to the Settings -> Main tab.

If it's not 1.0.0-beta-20090614 you'll need to update.

- Ben


RE: SQL error when using ft_api_check_submission_is_unique - msaz87 - Sep 1st, 2009

It looks like I'm running beta version is 1.0.0-beta-20090815 -- I'll go ahead and update that and see if it makes the difference.

That's odd it's not doing it for you, I just tried again, thinking I maybe changed something since I started the thread, but I still get the error if I type random stuff into the field and pick something from the drop down.

But I'll update the API and let you know if that solves it. Thanks for all your help!


RE: SQL error when using ft_api_check_submission_is_unique - Ben - Sep 1st, 2009

Hmmm! Nevermind - that's more up to date than my version! I'll get back to you...


RE: SQL error when using ft_api_check_submission_is_unique - Ben - Sep 1st, 2009

Ah... I see the problem.

Try entering the database column name instead of the form field name for the KEY of the $criteria hash. That error message appears when the key is invalid.

I've logged this as a bug & I'll fixed it in a future version of the API.

- Ben


RE: SQL error when using ft_api_check_submission_is_unique - msaz87 - Sep 1st, 2009

Changing the KEY got rid of the sql error, but I'm still having some troubles...

While I no longer get errors, I just get the **This email already exists** (submission isn't unique) error... regardless of the entry. I wiped the form clean of submissions and still nothing.

Here's the change I made to the code:

PHP Code:
$criteria = array(
  
"col_1" => $_POST["email"]
); 

EDIT: If it's important to note, the data type for the column is set as "string"

And I also modified the email input itself from
Code:
    <input type="text" name="email" size="30" value="<?=htmlspecialchars(@$fields["email"])?>">

To without the value at all.

Here's the demo again... http://fasports.com/test/test.php

Thanks for your help!


RE: SQL error when using ft_api_check_submission_is_unique - azparrothead - Sep 2nd, 2009

I also am getting the submission is not unique no matter what key(s) I provide ....if they are unique or not.... following this thread closely!

THANKS!


RE: SQL error when using ft_api_check_submission_is_unique - Ben - Sep 5th, 2009

Hey guys,

Sorry for not responding sooner.

I just checked it out and it seems to work okay... however, there was one thing that wasn't terribly good: the function won't take into account the CURRENT submission. In other words, when you first hit the page & run the test it'll work fine (i.e. correctly figure out whether the submission is unique or not based on your criteria). However, after the page values has been updated, that information is now stored in the database. So if you were to return to the page where you were running your test, the function would now incorrectly think that the submission is NOT unique - because it will accidentally compare it against itself. (Hope this is clear...)

What I'm going to do is add an additional optional parameter to that function that lets you specify the current submission ID. The function will use it to test all OTHER submissions in the database and prevent it ever testing against itself.

I'm just looking at the API now. I'll make an update tonight or tomorrow.

- Ben


RE: SQL error when using ft_api_check_submission_is_unique - azparrothead - Sep 5th, 2009

Thanks Ben!


RE: SQL error when using ft_api_check_submission_is_unique - Ben - Sep 5th, 2009

Hey guys,

msaz: try downloading the latest version of the API (http://docs.formtools.org/api/) and changing your function call line to this:

PHP Code:
if (ft_api_check_submission_is_unique(28$criteria$fields["form_tools_submission_id"])) 

Let me know how it goes! Smile

- Ben