I have a html table that is converted to JSON and sent over via AJAX to PHP. I've decoded the JSON object and now have a PHP array. I'd like to insert this array or rather the contents of it into a MySQL database.
I'm confused on some of the methodologies out there. what is the ideal method to prevent SQL injection? I see a number of methods that look like so;
foreach ($array as $key => $value)
{
$price = $array["price"][$key];
...................................
}
this doesn't seem to work, or at least I can't get php to print or echo out what $price is.
I've tried this:
foreach ($array as $key => $value)
{
$price = $value["price"];
...................................
}
This i can get echo or print_r to display the value.
First question is: what is the purpose of $key here in terms of inserting these values into MySQ? Second is: why doesn't the first one return the expected result, like that of the second code snippet? echo should display the value of $price? Lastly, from this assuming both methods are valid, an insert statement like below is correct for actually pushing the data into MySQL?
$sql = mysql_query("insert into Daily_Requests values ('','$price','$item','$etc...','$etc....')");
Regards
EDIT
Here is my JSON:
[{"Price":"5000","Manufacturer":"Newton","Model":"84x26x10 43u","Model_info":"Newton 84x26x10 43u","Type":"Rack","Height_in":"83.97637795","Height_mm":"2133","Width_in":"25.98425197","Width_mm":"660","Description":"Newton 84x26x10 43u","Depth_in":"10","Depth_mm":"254","Mount_Type":"Floor Mount","Rack_UNITS":"43","Rack_INSIDE_HEIGHT_mm":"1911","Rack_INSIDE_WIDTH_mm":"584","Rack_INSIDE_DEPTH_mm":"","ASSET_TYPE":"Rack","Phases":"","Status":"","Date":"2017-01-11","Submitted":"","Image File / Web Info":"","Site":"Orlando"}]