MySQL Queries w/ Arrays problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Xelmepa
Forum Commoner
Posts: 41
Joined: Sat Aug 24, 2002 3:02 pm
Location: Athens, Greece
Contact:

MySQL Queries w/ Arrays problem

Post by Xelmepa »

Hey,

I am writing a login script for a program of mine. In the environment I was testing I had PHP 4.0.6, but moving to my clients box, I encountered the standard problem , since he had PHP 4.2.3.

Now, my problem was with the MySQL query. The actual problem was with ""s and ' ' s.

My original code was:

Code: Select all

$query = "SELECT * FROM admins WHERE usr='$username' AND pwd='$password'";
Then I had to use the POST array, which would mean that I would have to make my variables from $username to $_POST['username'] or $_POST["username"], and the same for password. However both of the quotation makrs are used from before, so using them inside the query would get things screwed up (cut the var in half, getting an error).

I know I can change the names of the form objects, so that I don't have to use quotes in the array, but I am sure there's another way.

Thanks in advance,
Xelmepa
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

try the curly bracket syntax:

Code: Select all

$query = "SELECT * FROM admins WHERE usr='{$_POSTї'username']}' AND pwd='{$_POSTї'password']}'";
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

One more options is...

Code: Select all

$query = "SELECT * FROM admins WHERE usr='".$_POSTї'username']."' AND pwd='".$_POSTї'password']."'";
Cheers,
BDKR
Post Reply