View Full Version : A very silly query question...

11-10-2007, 01:10 PM

I have a query:

$SQL = "SELECT * FROM table WHERE id=".$_GET['id'];

But if I add order by to it:

$SQL = "SELECT * FROM table WHERE id=".$_GET['id'] Order by table_id;

It fails? I know it's something to do with the " being out of place, but surely it has to be there?

Thank you

11-10-2007, 01:33 PM
$SQL = "SELECT * FROM table WHERE id='".$_GET['id']."' Order by table_id";

11-10-2007, 08:17 PM
a better way to do it I think is this:

$SQL = "SELECT * FROM table WHERE id='$_GET['id']' Order by table_id";

11-10-2007, 08:27 PM
That will actually generate a php parse error, because php needs help in figuring out what part of that is the array variable. This will work however -

$SQL = "SELECT * FROM table WHERE id='{$_GET['id']}' Order by table_id";