开发者

Results not expected if/else

开发者 https://www.devze.com 2023-02-19 17:22 出处:网络
this is my database prod - id, title, code uname - id, email, name, code ======== edited ============ problem:

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 a开发者_运维技巧nd 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!


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!


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 $ -.-


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消