I have a slightly frustrating problem... I'm sending a form value to PHP via AJAX and that seem to work fine. When I do var_dump in PHP I see my values I can also set a variable and echo it correctly. However, the line
$prod_id=$_POST['product'];
causes an uncaught type error in the browser. If I just set the variable with text in PHP everything works fine. To conclude, this piece of code works fine:
$prod_id=("Slab Skate");
$selected_customers = mysqli_query($link,"SELECT * FROM customers
INNER JOIN cust_products on cust_products.cust_id=id
INNER JOIN products on products.prod_id=cust_products.product_id
WHERE products.prod_name='$prod_id'");
This code causes uncaught typerror:
$prod_id=$_POST['product']
Same SQL statement as above. If I do
var_dump ($prod_id);
after setting it with $_POST I get:
string(10) "Slab Skate"
My form data in network headers tab of Chrome developer tools say:
product:Slab Skate
I don't get it...
Thanks in advance for any tips.
Update and some clarifications. The error I get is this: "Uncaught TypeError: Cannot read property 'documentElement' of null" which is a Javascript error coming from a function later in the code. However, since the whole thing works if I "hardcode" the variable instead of setting it from $_POST my assumption was that the error must reside in PHP. But maybe that's not the case...
What I'm doing is the following: posting a form value to PHP -> use value to select from my_sql and prepare an XML output. So far so good, (I can see the xml output in Chrome dev tools) but then I go back to a javascript to fetch the xml output from my PHP file and then it fails. When thinking about it, it's rather obvious why it works with a "hardoded" variable and not with the $_POST set one. So, I see two solutions either set the PHP variable in my_sql or using javascript more intelligently. Do anyone have a smart solution? I could post all the code, but it's quite long.
Second update: I solved the issue by writing an xml file to the server instead of trying to download it from the php file. Then my java function can process the xml correctly. It does work, but I'm not sure how well it scales? It must be better to process the xml output from PHP directly rather then saving it to file first and then process. But, I have no insight on how big the difference is...
/Tim