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

11-10-2007, 02: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, 02:33 PM
$SQL = "SELECT * FROM table WHERE id='".$_GET['id']."' Order by table_id";

11-10-2007, 09: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, 09: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";