Jump to content

sql query


ldoozer

Recommended Posts

Hi all, please could somebody help me get this query to work.

 

I need to add ORDER BY SportTitle ASC to the end but can not get it to be valid.

$query = "SELECT * FROM sports s, categories c, sport_catog sc WHERE s.SportId = sc.SportId AND c.CategId = sc.CategId AND c.CategId = ".$_GET['catog'];

Link to comment
Share on other sites

$query = "SELECT * FROM sports s, categories c, sport_catog sc WHERE s.SportId = sc.SportId AND c.CategId = sc.CategId AND c.CategId = ".$_GET['catog']." ORDER BY xx.SportTitle ASC";

 

replace the xx with the alias of which table SportTitle is located in.

Link to comment
Share on other sites

$query = "SELECT * FROM sports s, categories c, sport_catog sc WHERE s.SportId = sc.SportId AND c.CategId = sc.CategId AND c.CategId = ".$_GET['catog'] . " ORDER By s.SportTitle ASC";

 

Also be wary of SQL Injection with including the $_GET directly into the sql like that.

Link to comment
Share on other sites

$query = "SELECT * FROM sports s, categories c, sport_catog sc WHERE s.SportId = sc.SportId AND c.CategId = sc.CategId AND c.CategId = ".$_GET['catog'] . " ORDER By s.SportTitle ASC";

 

If Someone entered 1 OR 2 = 2 into the catog parameter, what would that make your SQL statement?

This:

WHERE s.SportId = sc.SportId AND c.CategId = sc.CategId AND c.CategId = 1 OR 2 = 2 ORDER By s.SportTitle ASC";

 

Which would nicely return every row in your database, because 2 will always equal 2....?

 

 

Just check that your $_GET['catog'] is what you want it to be before you start pumping it into SQL statements

Link to comment
Share on other sites

sql injection is a bad thing.

 

basically you don't want to pass direct variables through your URL.

 

imagine soemone passing username and password in the URl.

 

someone just has to enter 'or1='1  as the password string in the URl and they are in.

 

this can cause problems with many aspects, but the most obvious one for people to see is a username password example.

 

 

here is a better description.

http://www.unixwiz.net/techtips/sql-injection.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.