Reply to Re: Forms...and WHERE in mysql

Your name:

Reply:


Posted by Rik Wasmus on 12/31/07 11:21

On Sat, 29 Dec 2007 01:33:01 +0100, Michael Fesser <netizen@gmx.de> wrot=
e:

> .oO(jpyers@gmail.com)
>
>> $result=3Dmysql_query("SELECT * FROM members
>> WHERE username=3D"$_POST[username]"");
>>
>> Your quotes are messed up, doing what sskaje said should fix your
>> problem.
>>
>> $result =3D mysql_query("SELECT * FROM members WHERE username=3D`
>> $_POST['username']`");
>>
>> That should fix your problem.
>
> Nope. It will cause a parse error because of the single-quoted array
> index inside of a double-quoted string. Additionally it will cause an
> SQL error because a backtick (`) is not a valid string delimiter.
>
> Correct:
>
> $result =3D mysql_query("
> SELECT *
> FROM members
> WHERE username =3D '$_POST[username]'
> ");

Which will probably give a notice the constant 'username' is not defined=
..

> or
>
> $result =3D mysql_query("
> SELECT *
> FROM members
> WHERE username =3D '{$_POST['username']}'
> ");

That's the one.

> Of course this won't fix the SQL injection problem ...

Very true. And a 'SELECT * ' should never be used in production, only fo=
r =

testing purposes. Naming the fields you should have will both ease the =

load on the server and cause a transparant failure instead of an obscure=
=

one on a table alteration.
-- =

Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация