What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    How to insert first name and last name into the mysql database

    Asked by Alidad on December 18, 2012 at 12:51 AM

    I'm trying to figure out how to insert first name and last name into the mysql database after submit subscriber payment.

    Before to do that, let say that full name tag name is {fullname12} as " john doe"

    and then to seprate firt name and last name it should be like this

     

    {fullname12:first}

    {fullname12:last}

     

    My question is that how can i write php code to identified each each POST data with a variable from [fullname12:....} before create insert database statement!

     

    AM

  • Profile Image

    Answered by fxr on December 18, 2012 at 01:54 AM

    Hi Alidad,

    It is probably better not to guess these php variable names based on tag name.

    --

    Just dump the post variables to a php file containing <? print_r ($_POST); ?>  this will list all the variables being made available by your form.

    http://www.jotform.com/help/51-How-to-Post-Submission-Data-to-Thank-You-Page

    --

    If you can't figure it out, let us know and we can get the variable name for you.

     

  • Profile Image

    Answered by Alidad on December 18, 2012 at 01:02 PM

    I'm sorry I'm lost on this part, i definity need help becuase i can't figure out this. can you possible to write the sample of variable please thanks. 

     

    AM

  • Profile Image
    JotForm Support

    Answered by jonathan on December 18, 2012 at 02:51 PM

    @AM

    Please test submit this form http://jotformpro.com/form/23503408907957 . This is the PHP code I used 

    Using this guide https://www.jotform.com/help/51-How-to-Post-Submission-Data-to-Thank-You-Page you should be able to do this also.

    Please inform us if you have further inquiry.

    Thanks.

  • Profile Image

    Answered by Alidad on December 18, 2012 at 04:22 PM

    Thank you so much for your response, so base on my side i see the jotform code as 

    Array (

    [submission_id] => 221616177352920552

    [formID] => 23516673638158

    [ip] => 68.50.29.253

    [fullname1] => Array ( [0] => Alidad [1] => Modjtabai )

    [address4] => Array ( [0] => 13928 main road [1] => [2] => Germantown [3] => MD [4] => 20874 [5] => United States ) [email3] => username@email.com

    )

    is going to be like this

    <?php

    $answer=$_POST

    url11= "http://www.url.com

    $var1="?fullname1[first]=".urlencode($answers[fullname1][0]);

    $var2="?fullname1[last]=".urlencode($answers[fullname1][1]);

    $var3="?address4=".urlencode($answers[address][1]);

    $$url2=$url11.$var1.$var2.$var3;

    header('location:$url12");

     

    is this is correct! if so, how can i write insert code with first name and last name seperate for mysql

    like this 

     

    mysql_query("INSERT INTO `table_name` (submission_id, formID, IP, 

                                                                              first, last,  email, phone, subject, message) 

                                   VALUES ('$submission_id', '$formID', '$ip', 

                                                     '$name', '$email', '$phonenumber', '$subject', '$message') ") 

     

    pleae clear me about this thanks.

     

    AM

  • Profile Image
    JotForm Support

    Answered by jonathan on December 18, 2012 at 05:33 PM

    If I understand the sql query correctly, it is supposed to be like this...

     

    mysql_query("INSERT INTO `table_name` (submission_id, formID, IP, 

     

                                                                              first, last,  email, phone, subject, message) 

     

                                   VALUES ('$submission_id', '$formID', '$ip', 

     

                                                     '$firstname', '$lastname', '$email', '$phonenumber', '$subject', '$message') ") 

    The table column id should match the field names/values index count/number. i.e. in your insert query.. the first,last column id do not have a match in the values

     

    Thanks.

     

  • Profile Image

    Answered by Alidad on December 18, 2012 at 08:03 PM

    where does $firstname, $lastname comes from when when the variable called fullname1[first] or fullname1[last]?

     

    AM

  • Profile Image
    JotForm Support

    Answered by jonathan on December 18, 2012 at 08:20 PM

    I am sorry for the confusion. I was merely describing the syntax for the sql insert statement.

    You can replace the '$firstname', '$lastname', ' variables to the appropriate one on your sql statements. (i.e. $var1, $var2). 

    This is a bit of programming (PHP, SQL) operation, -- perhaps a verse programmer can help you do it on your application.

    Thanks.

  • Profile Image

    Answered by Alidad on December 19, 2012 at 08:02 PM

    As for city, state and zip code do i need to write like this

    $var2="?address4[city]=".urlencode($answers[city][2]);

    $var3="?address4[state]=".urlencode($answers[address4][3]);

    $var4="?address4[zipcode]=".urlencode($answers[address4][4]);

     

    Base on what i ahve variable name

     

    Array ( [submission_id] => 221772933352590271 [formID] => 23516673638158 [ip] => 68.50.29.253 [fullname1] => Array ( [0] => john [1] => doe ) [address4] => Array ( [0] => 544 river bend rd [1] => [2] => great falls [3] => Maryland [4] => 22066 [5] => United States )

    is this correct!

     

    Alidad

  • Profile Image
    JotForm Support

    Answered by idarktech on December 19, 2012 at 10:00 PM

    Hi Alidad,

    It should be like this:

    $var2="?address4[city]=".urlencode($answers[address4][2]);

    $var3="?address4[state]=".urlencode($answers[address4][3]);

    $var4="?address4[zipcode]=".urlencode($answers[address4][4]);

    I have bolded the error part, yours is city it should be address4. Thanks!

     

  • Profile Image

    Answered by Alidad on December 19, 2012 at 11:48 PM

    thank you so much for your response, I just have one more question, inserting database worksing great, but when is see the address, in address column showing three words and between each word showing ( + ) for sample the address is "345 main stree" but in database showing "345 + main + street" how can i get ride of those (+) sign!

     

    Alidad

  • Profile Image
    JotForm Support

    Answered by idarktech on December 20, 2012 at 12:08 AM

    Hi Alidadm

    It is because of the urlencode, urlencode() function replaces spaces with '+' symbol. Try removing it that might help, but I am afraid that your prepopulation will not work. How about using rawurlencode() ? Example:

    $var2="?address4[city]=".rawurlencode($answers[address4][2]);

    See if this helps. Thanks!