Send Dynamic form information to database

this is my code
[php] | jQuery And PHP Dynamic forms input{border:1px solid #ccc;padding:8px;font-size:14px;width:300px;}.submit{width:110px;background-color:#FF6;padding:3px;border:1px solid #FC0;margin-top:20px;}
Add | Remove | Reset
[/php] how can i send this form info to my database. it's just show me a alert of info. [alert(answers);] help plz

in php to send form info to a database you have to reference the action in your form. something like then run a mysql_query to place your values into your database.

i can send data to my database
but i want to send a dynamic form info to database
like that code in first post.
please try that code and help me

You need to send it to a php script that will upload it.

As far as that JavaScript goes you need to do some tweaking because all the input fields are named “dynamic[]”. You will need them to be named “dynamic[0], dynamic[1], dynamic[2], etc.” for however many they decide and then probably just send a number along to tell php how many inputs there are.

I also noticed when you add an input for the first time it skips to 3, that may cause an issue…

For your JavaScript, to change the name I would use the i variable in the name field…

$('#add').click(function() { $('<div><input type="text" class="field" name="dynamic[' + i + ']" value="' + i + '" /></div>').fadeIn('slow').appendTo('.inputs'); i++; });

Well, to save form info in a database, there are actually many ways to do it.

The first is standard form processing that is done using PHP as Journeyman stated.
You would just have your JS post out to a PHP file that would use MySQL or SQL and
pull the values from the page and store them into the database. Lots of info on this site
about how to do that. (Try search function to locate them.)

The second would be to use JS only use JQuery/AJAX and write to the database directly. Most of
the code I have seen does not use this as it is client side and can be hacked with ease. The
PHP version runs server-side and is hard to hack.

To call the PHP code with JQuery (the call is client-side, the processing is server-side so secure), you
use something like $.post(“somepage.php”); in your JS/JQuery code to call the page.

Here is a sampler of how it looks:
$.post(‘scripts/somedatabasefunction.php’, {variabletopost: valuetopost}, function(){
//successful ajax request (the above sends the value “valuetopost” for the variable “variabletopost”)
alert(‘error… ohh no!’);

hope that helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service