GetDotted Domains

Viewing Thread:
"Muh, PHP / MySQL"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Wed 19/01/05 at 00:18
Regular
"previously phuzzy."
Posts: 3,487
I'm having a small issue with using the superglobals of PHP inside my MySQL queries. This :

$query = "SELECT customerPass FROM customers WHERE customerUsername = $_POST['username']";

Leads so jovially onto this :

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /the/file/is_here/darktest.php on line 24

Thoughts? It works fine when I just use '$username'.

p/h
Wed 19/01/05 at 08:04
Regular
"Eff, you see, kay?"
Posts: 14,156
I usually find problems with echo "$_POST['var']";, I find the way to do it is echo "$_POST[username]";, or close your quotes and use dots.
Wed 19/01/05 at 00:38
Regular
"NULL"
Posts: 1,384
AliBoy wrote:
> Beaten to it by Garin. :-)

Lol, ditto, but ideally you should have single quotes (') around a value on a WHERE expression in MySQL. Along with the correct string escaping etc, it stops people "modifying" your MySQL query.
Wed 19/01/05 at 00:36
Regular
"NULL"
Posts: 1,384
phuzzy wrote:
> $query = "SELECT customerPass FROM customers WHERE
> customerUsername = $_POST['username']";


Try instead:

$query = "SELECT customerPass FROM customers WHERE customerUsername = '".$_POST['username']."';";
Wed 19/01/05 at 00:32
Regular
"Picking a winner!"
Posts: 8,502
Beaten to it by Garin. :-)
Wed 19/01/05 at 00:32
Regular
"Devil in disguise"
Posts: 3,151
$query = "SELECT customerPass FROM customers WHERE customerUsername = ${_POST['username']}";

or better

$query = "SELECT customerPass FROM customers WHERE customerUsername=".$_POST['username'];

Although you shouldn't throw GET/POST data into queries like that in the first place without validating it in some way.
Wed 19/01/05 at 00:19
Regular
"gsybe you!"
Posts: 18,825
DAMN! Those superglobals
Wed 19/01/05 at 00:18
Regular
"previously phuzzy."
Posts: 3,487
I'm having a small issue with using the superglobals of PHP inside my MySQL queries. This :

$query = "SELECT customerPass FROM customers WHERE customerUsername = $_POST['username']";

Leads so jovially onto this :

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /the/file/is_here/darktest.php on line 24

Thoughts? It works fine when I just use '$username'.

p/h

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

First Class!
I feel that your service on this occasion was absolutely first class - a model of excellence. After this, I hope to stay with Freeola for a long time!
Easy and free service!
I think it's fab that you provide an easy-to-follow service, and even better that it's free...!
Cerrie

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.