ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to Insert data to database via EE

April 09, 2008 7:07pm

Subscribe [6]
  • #1 / Apr 09, 2008 7:07pm

    joel_smith

    92 posts

    I am trying to have customers enter information into a form, and then enter that information into a database table after the customer clicks submit.  I have been working on this for days and cannot figure out how to do the insert - please help!

     


    <form class=“wufoo leftLabel” enctype=“multipart/form-data” method=“POST” action=”<?php $PHP_SELF ?>”>
    <ul>
    <li id=“fo1li2”
    class=”  ” >

    <label class=“desc” id=“title2” for=“Field2”>
    Name
    *
    </label>


    <input id=“custfirst”
    name=“custfirst”
    class=“field text” size=“12”
    tabindex=“1”
    value=””  />
    <label for=“Field2”>First</label>

    </form>


    <?php
    if (!$_POST[‘submit’])
    {
    $custfirst=($_POST['custfirst']);

    //open connection
    $connection = mysql_connect('mysqlserver', 'uname', 'pwd');

    //select db
    mysql_select_db('database');

    $insertstatement= "INSERT INTO custsignup (name) VALUES ('$custfirst')";

    //execute insert statement
    $result = mysql_query($insertstatement);

    mysql_close($connection);
    }

    ?>

  • #2 / Apr 09, 2008 7:20pm

    Greg Aker's avatar

    Greg Aker

    6022 posts

    Here’s a link to the Database Class:
    http://expressionengine.com/docs/development/usage/database.html

    If I were you, I’d look into doing this with EE tags.  You can use the Solspace Freeform module to collect this information, or just use the mailing list signup form, found in the docs.

    Hope that helps,

    -greg

    I am trying to have customers enter information into a form, and then enter that information into a database table after the customer clicks submit.  I have been working on this for days and cannot figure out how to do the insert - please help!

     


    <form class=“wufoo leftLabel” enctype=“multipart/form-data” method=“POST” action=”<?php $PHP_SELF ?>”>
    <ul>
    <li id=“fo1li2”
    class=”  ” >

    <label class=“desc” id=“title2” for=“Field2”>
    Name
    *
    </label>


    <input id=“custfirst”
    name=“custfirst”
    class=“field text” size=“12”
    tabindex=“1”
    value=””  />
    <label for=“Field2”>First</label>

    </form>


    <?php
    if (!$_POST[‘submit’])
    {
    $custfirst=($_POST['custfirst']);

    //open connection
    $connection = mysql_connect('mysqlserver', 'uname', 'pwd');

    //select db
    mysql_select_db('database');

    $insertstatement= "INSERT INTO custsignup (name) VALUES ('$custfirst')";

    //execute insert statement
    $result = mysql_query($insertstatement);

    mysql_close($connection);
    }

    ?>

  • #3 / Apr 09, 2008 7:47pm

    joel_smith

    92 posts

    Ok, I implemented the db class info into the bottom of my form - is this the correct placement?  I ran across the db class today and tried something similar, but I could not get it working. When I preview my template it is showing the function, which it should not. Also, where can I find the Solspace Free Forms?

    </form>

    function database()
    {


    global $DB;

    $data = array('custfirst' => $name);

    $sql = $DB->insert_string('custsignup', $data);

    $DB->query($sql);


    }

  • #4 / Apr 09, 2008 7:56pm

    Lisa Wess's avatar

    Lisa Wess

    20502 posts

    Hi, Joel—

    Why not use an existing solutions, such as a weblog with a SAEF or FreeForm?

  • #5 / Apr 09, 2008 8:01pm

    Mark Bowen's avatar

    Mark Bowen

    12637 posts

    As said above Freeform, the SAEF or a weblog will do all this for you but I am just wondering what database do you need this to go into? Is this the ExpressionEngine database or another one that is separate from the ExpressionEngine database and if so what exactly is it that you are trying to accomplish?

    Actually looking at your code above I guess this is some sort of signup form?

    Also being the eagle-eyed spy that I am 😉 I noticed that you have a form class of wufoo? What you are trying to do doesn’t have anything to do with the wufoo forms does it?

    Anyway a little more info would be helpful as what you are trying to do might already be possible with existing features.

    Hope that helps.

    Best wishes,

    Mark

  • #6 / Apr 09, 2008 10:57pm

    Sue Crocker's avatar

    Sue Crocker

    26054 posts

    Joel, you can find the Solspace Freeform offering here.

  • #7 / Apr 10, 2008 2:19am

    Ingmar's avatar

    Ingmar

    29245 posts

    What Sue says. Heartily recommended.

  • #8 / Apr 10, 2008 4:23pm

    joel_smith

    92 posts

    Thanks for all your help!  Like Mark said, I am trying to implement a wufoo form b/c the client liked the way it looked.  So I took all your advice and looked into implementing it with a SAEF.  Using the info here :http://expressionengine.com/docs/modules/weblog/entry_form.html
    I implemented the wufoo form w/the exp:weblog:entry_form tags (I think!)

    However, I am finding difficulties in transferring the data captured in the form to the weblog.  The only items that are inserting to the exp_weblog_data table are the title and the url.  Is there a tag I can use to have the fields insert into this table?

    Here is what I have:

    {exp:weblog:entry_form weblog="register" return="site/index" preview="site/entry"}      
    
    <input type="hidden" id="title" name="title" value="Registration" />
           
     <form class="wufoo leftLabel">
    <ul>
    <li id="fo1li2"
    class="   " >
    
    <label class="desc" id="title2" for="Field2">
    Name
    <span class="req">*</span>
    </label>
    
    <span>
    
    
    <input id="custfirst" 
    name="custfirst"
    class="field text" size="12" 
    tabindex="1"
    value="" onclick="setcustfirst(field_id_17)" />
    <label for="Field2">First</label>
    </span>
  • #9 / Apr 10, 2008 4:45pm

    Lisa Wess's avatar

    Lisa Wess

    20502 posts

    Hi, Joel -

    The SAEF automatically handles that information and passing it into the database - that’s the point of the form, after all.  Have you tested with the SAEF right out of the docs to ensure that it works, before customizing it?

  • #10 / Apr 10, 2008 4:57pm

    Mark Bowen's avatar

    Mark Bowen

    12637 posts

    Hi Joel,

    I thought I would be right with the wufoo thing 😉 Eagle eyed I am 😉

    If the client just likes the look (style) of the form that wufoo creates then don’t worry. You can make an SAEF look like anything you want. Both Wufoo and the SAEF are after all both just forms so you can take the rendered look of the Wufoo form and apply just the same thing to your SAEF.

    As Lisa has said the best thing to do would be to literally take the code from the documentation for the SAEF changing any items you need to and see what you get. The rest then really is just down to styling. I personally have styled the SAEF in so many ways now that I forget it is even an SAEF when I look at them.

    Hope that helps.

    Best wishes,

    Mark

  • #11 / Apr 10, 2008 5:01pm

    joel_smith

    92 posts

    Yes, I copied the SAEF example into a template and tested to verify that it would enter the data into the correct table fields.  That worked fine, but when I try to add the SAEF example with the form that the client created it is not entering the data.

  • #12 / Apr 10, 2008 5:06pm

    joel_smith

    92 posts

    Note to self: refresh before posting - I didn’t see Mark’s comment. 

    And I believe what you described is what I’m attempting to do - modify style of the SAEF - but I could be way off base. 

    Is this what needs to be modified to commit the data?

    onclick="setFieldName(this.name)"

    I’m not sure what my next step is to style the SAEF to make it look like the spec I was given…any ideas?

  • #13 / Apr 10, 2008 5:10pm

    Mark Bowen's avatar

    Mark Bowen

    12637 posts

    Hi Joel,

    This is most likely because you are trying to do things slightly backwards on this one 😉

    You have a field in your wufoo form named custfirst. If you want that field to exist in your SAEF then all you have to do is create a custom field in your weblog called this and it will be automatically placed into your SAEF.

    The best thing is to literally (for now) forget about the wufoo form as all you really need from that is the styling right?

    For now if you can get the SAEF working and inputting data into fields as you need then the styling can come later. Make sense?

    To ask again though, is this just for a mailing list sign up form though?
    If so then you really couldn’t do much better than the Freeform Module from Solspace. This allows you to create forms with as many fields as you desire and is exceptionally powerful.

    Once you have a Freeform form working (forget about styling for now) then you can style to taste with CSS to however you want.

    Hope that helps.

    Best wishes,

    Mark

  • #14 / Apr 10, 2008 5:12pm

    Mark Bowen's avatar

    Mark Bowen

    12637 posts

    Oops I was posting and didn’t see your question. Do you have a link to the form created by Wufoo and what it looks like at all?

    Really all you need to do on this is take the CSS styling from the wufoo form and apply it to the SAEF. The SAEF code on its own doesn’t have any form of styling and so this is down to the individual which is great because you can make a form look and behave exactly the way you want.


    Best wishes,

    Mark

  • #15 / Apr 10, 2008 6:34pm

    joel_smith

    92 posts

    I understand what you mean about going through the process backward 😉  its definetly getting frustrated. 

    Here is the html integrated into my site: http://devel.pixelenvy.net/projects/theindyannex/ExpEng/index.php?/site/Registration/

    I tried adding the custom fields and having the SAEF pull those for the data but I had a hard time getting the styling correct.  Especially on the form field sizes.  Is there an easy way to trim these down without writing a lot of {if} statements?

    Thanks so much for all your help!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases