jquery - Invalid argument supplied for foreach() AJAX to PHP -
O people, I am trying to pass the value of the farm field through ARX in a PHP file that writes the data. A MySQL database.
I have my standard form with a set of field entries:
& lt; Input type = "text" name = "rname []" & gt; & Lt; Input type = "text" name = "rDateS []" & gt; & Lt; Input type = "text" name = "RDATF []" & gt; & Lt; Input type = "text" name = "rocost []" & gt; I'm pushing these values by clicking on my PHP file $ ("# addRates_Submit"). Click (function () {var rName = $ ('# RNM'). Val (); var is RDTS = $ ('# RDDS'). Val (); var RDATF = $ ('# RDTF'). Val ( ); Var rCost = $ ('urphpfile', type: "post", data: $ .ajax post data $ .ajax for .val (); var (apc) = // server $. {"RName": rName, "RDateS": rDateS, "rDateF": rDateF, "rCost": rCost}, data type: "text", success: function (data) {// this AJAX request console.log (data ) Outputs; $ (HTML (' gt; & lt; p style = "color: #ffffff;" & gt; rates added. & Lt; / P & gt; & lt; / center & gt; ');}, Error: Function (errorThrown) {Console.log (errorThrown); $ (' # resultDiv '). Html (' a probl has happened to them. ' Error reversal response text); details are false;}}; // and ajax} // and process}}); // end rate submit
php file:
$ rName = filter_var ($ _ POST ["rName"], FILTER_SANITIZE_STRING); $ RDateS = Filter_ ($ _ POST ["rDateS"], FILTER_SANITIZE_STRING); $ RDateF = filter_var ($ _ POST ["rDateF"], FILTER_SANITIZE_STRING); $ RCost = filter_var ($ _ POST ["rCost"], FILTER_SANITIZE_STRING); Enter the foreign currency ($ key as $ RN name = & gt; $ n) {$ oaQuery = "Property_Solution (PID, R, Names, RDTS, RDTF, Arcot) values ('$ pInsertID', '$ n' , '$ RDateS [$ key]', '$ rDateF [$ key]', '$ rCost [$ key]') "; $ OaResult = mysql_query ($ oaQuery); }
I get the following error from the console log:
Invalid argument () on line for foreach () I have tried to add is_array ($ rName) and which takes away the error but the array does not post anything to DB. Is it possible to deposit form forest arrays through AJAX and then php knows what it is or do I need to be in the side of the array jQuery and then pass that JPApier array data into a php array.
If I insert this as a single question and do not do any array, then it works fine but it is never built like an array. (Side note: My form adds dynamically the field, when the user wishes every time that it adds the field set, then label it according to the names of RANMA [], RDATF [], RDATF [], and Arcast []
I think there are some problems with your code.
Most First, if you have $ ('# rName') you can only have 1 input because id should be uniq Second, if you use $ ('.r.name') then You can do a lot of input with the same class, but the code
Var RN name = $ ('# RNname'). Val ();
< P> Returns the value of the first input field only, and Finili, you get only values as a text and PHP only reads one variable, not an array. Must pass through and create a string like this:
var rname = ''; $ (".rname"). Each (function () {rname = rname = '& amp; ; Rname [ ] = '+ $ (This) .val ();});