Page 1 of 1

AJAXing MYSQL with PHP

Posted: Thu Jun 11, 2009 7:05 am
by gvkalra
Hi there.
Just a bit of help....

I have implemented AJAXing with MYSQL & PHP....It's going smoothly .... Just a bit of problem with MYSQL query....
my url is something like http://abc.com#xyz ..... I generate data based on that xyz.....xyz is the department

function getSummary($department) {
mysqlQuery = "SELECT * FROM table where dptlist=$department";
...
...
}

function getSummary($deparment) {
mysqlQuery = "SELECT * FROM table where dptlist=\"xyz\"";
...
...
}


The first function is not working while the second one is working ....... how to overcome this problem ???? ..... I don't want to explicitly mention $department in all my switch cases ...... ny help ???

Re: AJAXing MYSQL with PHP

Posted: Thu Jun 11, 2009 7:08 am
by jaoudestudios
Is $department a string or an integer?

if its a string your mysql query is wrong!

Re: AJAXing MYSQL with PHP

Posted: Thu Jun 11, 2009 7:13 am
by gvkalra
jaoudestudios wrote:Is $department a string or an integer?

if its a string your mysql query is wrong!

its a string with the data type VARCHAR in the MySQL database ....... what would be the correct query ??

Re: AJAXing MYSQL with PHP

Posted: Thu Jun 11, 2009 7:31 am
by jaoudestudios

Code: Select all

SELECT * FROM table where dptlist='$department'

Re: AJAXing MYSQL with PHP

Posted: Thu Jun 11, 2009 12:02 pm
by mikemike
And make sure you're escaping it first, incase someone works in the department of ' ";DROP TABLE users;SELECT * FROM table WHERE id="' :wink:

Re: AJAXing MYSQL with PHP

Posted: Thu Jun 11, 2009 11:48 pm
by jaoudestudios
mikemike wrote:And make sure you're escaping it first, incase someone works in the department of ' ";DROP TABLE users;SELECT * FROM table WHERE id="' :wink:
Haha :lol:

Yes this goes without saying!