On Sat, 2004-03-20 at 01:03, Chris Knipe wrote:
> Lo everyone,
> 
> I'm *baffled* completely.... I've never seen something like this before.....
> :((((  I tried this exact query from PHP, Perl, as well as the MySQL
> thingy... They ALL give the same result - it must therefore be my table....
> ...
> mysql> INSERT INTO Accounts (Username, Password) VALUES
> (Username='[EMAIL PROTECTED]', Password='password');
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> SELECT * FROM Accounts WHERE Username='[EMAIL PROTECTED]';
> Empty set (0.00 sec)
> 
> mysql>
> 
> HOWEVER....
> 
> mysql> SELECT * FROM Accounts WHERE Username='0';
> +---------+----------+----------+----------+----------+
> | EntryID | Username | Password | isActive | isCapped |
> +---------+----------+----------+----------+----------+
> |      48 | 0        | 0        | y        | n        |
> +---------+----------+----------+----------+----------+
> 1 row in set (0.00 sec)
> 
> There's my entry.  It's the row that was inserted, because I can see from
> the EntryID (Auto Increment).
> 
> Now, WTF is wrong here...   Nevermind what the value is I send to Username /
> Password, Mysql *ALWAYS* replaces the data specified with a 0.  Needless to
> say, due to the UNIQUE keys, I dont ever get the data into my table.... :(((

You are using the wrong syntax for what you want to do.  What you want
is this:

insert into table (username, password) values ('username', 'password')

Skip out the "username=" and "password=" part.  What you are ending up
doing here is that the values portion of the insert statement, these two
parts:
   Username='[EMAIL PROTECTED]'
   Password='password'
Are being evaluated as comparison expressions.  Since the string
'password' does not equal the value of the column Password (although
this seems like an odd syntax to allow without a where clause), the
value of these two columns is zero.  Simplified, your query ends up
being (after the expressions are evaluated):

insert into table (username, password) values (0, 0)

because both of the expressions you put in the values evaluate to 0.

I hope this is clear enough.

-- 
Andy Bakun <[EMAIL PROTECTED]>


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to