0

this is my database

prod - id, title, code

uname - id, email, name, code

======== edited ============

problem:

When I use email@email.com I always got response 1 - which mean it worked

When I use email1@email.com I'm able to add the same product over and over again and always got response 2 - which means something is wrong.

Any idea?

Thanks

edit == just fix the code and paste it once more. I have no syntax error.

edit again.

It's working now with some sql modification. First try using PHP had to study more.. Can't mention ur name one by one.. But again, Thank you!

joe
  • 1
  • 1

3 Answers3

2

What @nick rulez said is true, you forgot the $ sign.

edit: However, mysql_fetch_array will ALSO return results such as:

Array(
[0] => 'the@email.com'
[1] => 'name'
);

you should try using mysql_fetch_assoc, which will produce an array with the keys you're looking for.

Array(
[**email**] => 'the@email.com'
[name] => 'name'
);

Cheers!

bstpierre
  • 30,042
  • 15
  • 70
  • 103
fsodano
  • 548
  • 2
  • 8
  • mysql_fetch_array by default produces a combo array/hash structure, unless you specifically request only one of the two types. – Marc B Mar 24 '11 at 14:22
  • You are right, apologies. Nevertheless, it might be more efficient to just fetch the associative array, based on the code extract @joe posted. Cheers! – fsodano Mar 24 '11 at 14:51
0

if you compare 0 int value to a string value that is not a number the result will always be true

if(0 == "Hello") -> true

because the downcast from string to int returns true (0) and 0 == 0 always true

EDIT: okay yeah you only missed the $ -.-

sharpner
  • 3,857
  • 3
  • 19
  • 28
  • But why email@email.com always work but not with email1@email.com?? It's confuse me :( – joe Mar 24 '11 at 14:12
  • I bet you dont have email1 in your database, you're doing some pretty strange stuff, search for a email in the database, and after that comparing the email you got with the email you looked for, so if the email is not in the database, the first check is false, and that if the stuff check is true you get response 2 – sharpner Mar 24 '11 at 14:15
  • I have email1@email.com on my database with the same product code. While email@email.com have unique product code. I can't add same product using email@email.com [strange] – joe Mar 24 '11 at 14:18
0

What is this supposed to do?

if (user2 == "email")

You need a $ before user, and "email" should be $email, right?

Also, the code is ripe for sql injections. Escape all input variables with mysql_real_escape_string before you put them into queries (for more info: Protect against SQL injection).

Community
  • 1
  • 1
Jon
  • 428,835
  • 81
  • 738
  • 806