I have a two part question. I have this form that is being sent to a php script which in turn inserts the data to the database. For some reason the data only gets submitted to the database sometimes. Ive tried refreshing the page, opening a new tab, trying a new browser but i cant find out when/why the data only gets submitted some of the time. Im using relativly simple jquery code to submit the data this is what i have: $('form').submit(function() { var dataString=$(this).serialize(); $.post("scripts/submission.php", dataString , function(data){ //alert(dataString); } ); }); Code (markup): My other problem is i have a dynamic form. So depending on what the user selects from a drop down menu, new menus may appear or disappear. This works fine except i have cannot submit any data from one specific field. The field lists schools in a certain state. So when the users selects say 'new jersey' from one drop down a new drop down is shown with all of the schools in new jersey. When i go to submit the serialized form i did an alert to make sure the data was captured and it was. My only problem is that the php is not submitting it anytime i go to insert that field into the database. I checked the spelling and everything looks fine to me. When running properly all of the data is submitted to the database minus the school field (i just omit the school field for now because nothing gets submitted if i leave it in there). Here is all of my javascript code, most of it is just state changes for the form itself. $(document).ready(function(){ $('#schools').hide(); $('#manschool').hide(); $('#cantfind').hide(); $("#coachlevel").change(function() { postion(); getSchools(); middleSchool(); //cantFind(); }); $("#state").change(function() { getSchools(); }); function getSchools(){ var hs = $("#coachlevel").val(); var st = $("#state").val(); var dataString ="coachlevel=" + hs + "&state="+st; $.ajax({ type: "POST", url: "somescript.php", cache: false, data: dataString, success: function(msg){ $('#schools').show(); $('#schools').empty(); $('#schools').append(msg); cantFind(); } }); } function postion() { if($('#coachlevel').val()=='private') { $('#positionholder').hide(); $('#manschool').hide(); } else $('#positionholder').show(); } function middleSchool() { if($('#coachlevel').val()=='middleschool') { $('#manschool').show(); } else $('#manschool').hide(); } function cantFind(){ if(($('#coachlevel').val()=='college') | ($('#coachlevel').val()=='highschool')){ $('#cantfind').show(); } else $('#cantfind').hide(); $('#cantfind').click(function() { $('#school').remove(); $('#schoollist').append("<input type='text' name='school' id='manschool' value='Enter your schools name' size='40' />"); }); } $('form').submit(function() { var dataString=$(this).serialize(); $.post("process.php", dataString , function(data){ //alert(dataString); } ); }); }); Code (markup):
When i go to submit the form i did an alert on the serialized string and this is what i get firstname=&lastname=&gender=Male&sport=baseball&coachlevel=highschool&state=Iowa&school=North+Hunterdon+high&position=head This looks fine to me. On the php side ive been pulling each variable in via $_POST['varname']. I checked a 100 times and make sure for the school i have $_POST['school'] but still get no variable. Can anyone tell me why the school one is the only one i have a problem with? Wouldnt it be a problem with my php since I'm pretty sure the school variable is being sent properly?