Retrieving data from mysql using ajax weird problem!

Hi ,
I’m trying to fetch data from mysql ,
whene i type a simple query as “select * from table” and use var dump very thing goes right
but when i user more complex query as "select * from table where name = name and …
nothing comes back ?? (this works if I’m not using ajax).

is there any solution for this ?

I’m slightly confused as to your context - are you referring to ajax as in the client side technology “asynchronous javascript and xml” ? If yes, then absolutely nothing database related should get anywhere near your front end*

*Unless you’re creating a db admin script like phpMyAdmin ???

1 Like

I’m developing chat application using php and mysql (messages stored in mysql database) and jquey(ajax)
so i want my page to be refreshed every 5 seconds to print new messages , when i use simple query as i said before every thing works fine but when i use more complex query it returns nothing knowing that i have tried the same query in phpmyadmin and it works fine

Ok, cool so far. There’s a few things to check here though.

  1. I just want to be 100% certain that you’re not sending the SQL query from the javascript/jquery on the front end, but are instead composing your SQL query in PHP at the very least (assuming you’re not using a db lib to build the query for you).

  2. Do you have a logging solution written in to your php app yet? If not, you should (it’s more production friendly than accidentally leaving a var_dump() in your release candidate :wink: ) Here’s a good one: https://github.com/Seldaek/monolog also available on packagist if you’re using composer (recommended!)

  3. Log the query that you’ve built

  4. Log the mysql result set that comes back from the query

  5. Log the response body that you’d be returning to the ajax request - does it match the payload format that your jquery app is expecting? If not, fix up the payload and/or jquery so that they’re in sync

  6. Check the Content-Type that’s being returned with your payload - if php is throwing an exception, the content type could be getting forced to text/html instead of application/json (and the content body wont be JSON!)

  7. Log any exceptions!

  8. Use browser tools (firebug or developer tools in chrome) to verify what is being sent to the php server and what is coming back from the php server - this isn’t an alternative to the logging incidentally, as you’ll most likely still want some form of logging in production.

2 Likes

Can you post the exact code for the problem query?

1 Like

thanks for guiding me ,
i don’t know where the problem I’m beginner with ajax
but i solved this problem by using another query that do almost the same job ,
i don’t know where the problem I’m beginner with ajax

thanks for everyone that tried to help .

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.