We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42082
    • 72 Posts
    Hey guys modxnooby here agian..
    My modx system is just soo touchy. Any way I am creating a snippet to pull in a search from the page before and make it search the database this is what it looks like:

    <?php
    $sql=processSearch();
        printResults($sql);
    
    function processSearch() {
        $searchField=$_POST["search"];
        $sql="SELECT `name`, `video`, `image`
        FROM videos
        WHERE
        name LIKE '%$searchField%'";
        return $sql;
    }
    
    function printResults($sql) {
        $username="username";
        $password="password";
        $host="localhost";
        $dbname="database";
        $conn = mysql_connect($host, $username,$password);
        mysql_select_db($dbname);
        $result=mysql_query($sql,$conn);
        while ($row = mysql_fetch_assoc($result)) {
          print "<div class='tablecell'><a rel='prettyPhoto' href='" . $row["video"] . "' title='" . $row["name"] . "' alt='" . $row["name"] . "'><img src='[[++image-path]]" . $row["image"] . "'></a></div>";
        
        } 
       
    }
    ?>

    Now when i put a search in the search bar and click submit I get this Error:
    Fatal error: Call to undefined function processSearch() in public_html/core/cache/includes/elements/modsnippet/158.include.cache.php on line 7

    Now I went to the path it said to look in and this code was added to my snippet (without my knowing)

    function elements_modsnippet_158($scriptProperties= array()) {
    global $modx;
    if (is_array($scriptProperties)) {
    extract($scriptProperties, EXTR_SKIP);
    }


    This is some how making my script not function because when I tested this script without modx it worked. So I tried taking this code off my snippet then I saved it and retried my search. The search worked! smiley But then I did another search to make sure it worked and none of the search results showed up. sad So I am thinking that this code is needed for modx snippets. But it still is messing with my code.

    Can someone tell me what is wrong with my code?
      • 3749
      • 24,544 Posts
      That's just code that allows MODX to run your snippet from the cache file.

      Move your functions to the top of the script (just below the <?php).

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 42082
        • 72 Posts
        thanks Bob I tried what you suggested and got no results or the error. No idea why this is doing that but If you have any other ideas I would be happy to hear them.
          • 3749
          • 24,544 Posts
          Did you clear the cache. That really should have done it. In MODX snippets, functions need to appear in the code above the point where they are called or you get exactly that error message. You might try manually deleting all files in the core/cache directory.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting