Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Mysql database

  1. #1
    Join Date
    Apr 2007
    Posts
    21

    Default Mysql database

    Hi !
    Is it possible to put the form result into Mysql database using formmail.php ?

    Do you have advice or tips about how to do that ?
    I guess I need to convert my html form to a php form.

    Your Sincerely
    Andre

  2. #2
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Mysql database

    Hi,

    Is it possible to put the form result into Mysql database using formmail.php ?
    Yes. You need to write some PHP code and use the FormMail Hook system to do this.

    It's quite straightforward if you're a PHP programmer.

    Do you have advice or tips about how to do that ?
    First step is to create a PHP script that writes to the database the way you want. Say, from some fixed variable names or an array of values (better).

    Next, some small translation logic that takes the field values in FormMail and places them in the variables or the array.

    Finally, include the PHP script into the FormMail code using the Hook system. The Hook system isn't documented yet, but it's very simple to use: you set HOOK_DIR, place your script in that directory and name it so that it gets included automatically at the right point in FormMail's processing.

    I guess I need to convert my html form to a php form.
    No. The form is just a form. The logic is entirely within FormMail and your add-on PHP code.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Apr 2007
    Posts
    21

    Default Re: Mysql database

    Quote Originally Posted by russellr
    and name it so that it gets included automatically at the right point in FormMail's processing.
    I don't understand this part my friend. Shuld I name the script a specail name or what ?

  4. #4
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Mysql database

    Hi,

    That's correct.

    Name the script "fmhookprefinish.inc", it will then be automatically included just before the final page (e.g. good_url) is shown.

    If an error occurs in your script, it can call the error function, like this:
    PHP Code:
    Error("db_error","Failed to save data in database"); 
    You can just use the PHP $_POST array to get the field values, but that will not have all the derived fields and will not have the "cleaned" data values. FormMail does quite a bit of data "cleaning" to avoid injection attacks and other nasties.

    The array you want to use for getting your field values is "$aCleanedValues", like this:
    PHP Code:
    $email $aCleanedValues["email"]; 
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  5. #5
    Join Date
    Apr 2007
    Posts
    21

    Default Re: Mysql database

    ohhhhh my great GOD...it works.
    Your service is the best I ever have seen.
    Thank you so much for all help.

    Your Sincerely
    Andre

  6. #6
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Mysql database

    Excellent!
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  7. #7
    Join Date
    Apr 2007
    Posts
    21

    Default Re: Mysql database

    Hi Mr Robinson

    last question please.
    Is it possible to insert hidden derive_fileds fileds into database ?

    I have this hidden field in my form
    <input type="hidden" name="derive_fields" value="Nr=%nextnum%.%sec%"/>

    I have tryed to put "Nr" into a database but it did't work.

    Andre

  8. #8
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Mysql database

    Hi,

    "Nr" should be in the $aCleanedValues array.

    If it isn't, there are a couple of causes:
    1. It's empty (probably not the cause).
    2. You've listed it in the "Exclude" feature of "mail_options".
    $aCleanedValues doesn't include every data value. That's why it's called "CleanedValues".

    So, the way to handle this is to use the $aRawDataValues as an alternative source of field values. Like this:
    PHP Code:
    if (isset($aCleanedValues["Nr"]))
      
    $nr_value $aCleanedValues["Nr"];
    elseif (isset(
    $aRawDataValues["Nr"]))
      
    $nr_value $aRawDataValues["Nr"];
    else
      
    Error("missing_value","Nr has no value"); 
    BTW, special field values (like email and realname) are available in the global array $SPECIAL_VALUES.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  9. #9
    Join Date
    Apr 2008
    Posts
    9

    Default Re: Mysql database

    Quote Originally Posted by russellr View Post
    Hi,
    The array you want to use for getting your field values is "$aCleanedValues", like this:
    PHP Code:
    $email $aCleanedValues["email"]; 

    Is this in the form or the database connection information?

    Working through this but not successful yet.

    I've taken all of the php mysql setup from a working page (meaning it was saving to the database) and saved it as fmhookprefinishinc. Put it in a folder called SUB and changed the link in the fmform php page.

    The fmhookprefinish page is copied below:
    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_LLA = "*****";
    $database_LLA = "*****";
    $username_LLA = ""*****";";
    $password_LLA = ""*****";";
    $LLA = mysql_pconnect($hostname_LLA, $username_LLA, $password_LLA) or trigger_error(mysql_error(),E_USER_ERROR);
    ?>

    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "SignUp")) {
    $insertSQL = sprintf("INSERT INTO SUBSCRIBER (fname, lname, email, address1, address2, city, `state`, zip, comments, `date`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['fname'], "text"),
    GetSQLValueString($_POST['lname'], "text"),
    GetSQLValueString($_POST['email'], "text"),
    GetSQLValueString($_POST['address1'], "text"),
    GetSQLValueString($_POST['address2'], "text"),
    GetSQLValueString($_POST['city'], "text"),
    GetSQLValueString($_POST['state'], "text"),
    GetSQLValueString($_POST['zip'], "text"),
    GetSQLValueString($_POST['comments'], "text"),
    GetSQLValueString($_POST['date'], "date"));

    mysql_select_db($database_LLA, $LLA);
    $Result1 = mysql_query($insertSQL, $LLA) or die(mysql_error());

    $insertGoTo = "../thankyou.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
    }
    ?>
    It's not working and I'm getting emails but no DB info, thus I'm not getting an error as to where to look.

  10. #10
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Mysql database

    Hi,

    You generally cannot get software to work by cutting and pasting. You need to have some understanding of how the software works, what it is doing, and the structure of the language it is using (PHP in this case) to get modifications to work.

    No insult intended in any way - just telling you how it is.

    For example, a single character in the wrong place can stop an entire $50 million software project working or send a $10 billion rocket crashing into the moon.

    So, I recommend you hire a programmer to do this task for you (it is a simple task for even an inexperienced programmer).

    However, if you believe you'll be able to get through it yourself, I've quickly analysed the code you've posted, and where you have this:
    PHP Code:
    $_POST['fname'
    you need to replace it with this:

    PHP Code:
    $aCleanedValues["fname"
    And so on, with similar code.

    Note, however, I cannot guarantee I've understood your code correctly. As any programmer will tell you, unless I've made the modifications myself and tested them myself, I cannot be sure I've understood the existing code correctly.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Hook system and mysql database
    By onno in forum Community Support
    Replies: 14
    Last Post: 20-Sep-2010, 09:29 AM
  2. Updates to mySQL table ...
    By rogerfsmith in forum FormMail Subscription Support
    Replies: 1
    Last Post: 31-Oct-2006, 07:07 AM
  3. the same entry multiple times in my database...
    By tricianeill in forum Community Support
    Replies: 1
    Last Post: 30-Sep-2006, 02:14 AM
  4. Form results insert to mysql
    By BevO in forum FormMail Subscription Support
    Replies: 1
    Last Post: 22-Feb-2006, 11:40 PM
  5. mysql connect
    By moreover in forum FormMail Subscription Support
    Replies: 5
    Last Post: 23-Oct-2004, 10:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •