AJAXing MYSQL with PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gvkalra
Forum Newbie
Posts: 2
Joined: Thu Jun 11, 2009 6:57 am

AJAXing MYSQL with PHP

Post 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 ???
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: AJAXing MYSQL with PHP

Post by jaoudestudios »

Is $department a string or an integer?

if its a string your mysql query is wrong!
gvkalra
Forum Newbie
Posts: 2
Joined: Thu Jun 11, 2009 6:57 am

Re: AJAXing MYSQL with PHP

Post 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 ??
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: AJAXing MYSQL with PHP

Post by jaoudestudios »

Code: Select all

SELECT * FROM table where dptlist='$department'
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: AJAXing MYSQL with PHP

Post 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:
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: AJAXing MYSQL with PHP

Post 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!
Post Reply