We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13760
    • 3 Posts
    I’m quite new to MODx, I’m on a shared server, and I’m trying to connect from a web form I built to a database of contacts (I’d rather not use eForm because I built all of this before I moved to MODx).

    Currently the entirety of my form is stored in a snippet. The form’s action is

    <?php echo $_SERVER['PHP_SELF'];?>


    and the attempted connection is being done like so:

    $conn = mysql_connect('myhost', $secureuservariable, $securepasswordvariable); 	mysql_select_db('musicg_contacts');
    


    but when the form submits, it does not perform the action I’m asking it to, it just forwards to the index.

    Any help? PHP 5 and MySQL 5, Apache server, Safari 4 and Firefox 3.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Your form should have [~[*id*]~] as its action; let MODx sort out the correct URL. Your snippet would get the POST (and hopefully validate and escape it properly) and do the database stuff. When the snippet is finished, it can return some kind of success message.

      Snippets contain PHP code only; no HTML with inline PHP. MODx does not use that structure at all. The entire contents of the snippet is passed through the eval() function, so raw HTML code will just fail.

      Make sure you close your new database connection as soon as you are finished with it so that MODx doesn’t get tangled up with the wrong connection to the wrong database.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org