Jump to content

What's the difference...?


NoDoze

Recommended Posts

Between:

INSERT INTO tbl_auth_user SET user_id='$user_id', user_password='$user_password' , ID = '3'

 

and:

INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('user', PASSWORD('password'))

 

I know the top one is entering info based on form results.

And the bottom one is entering the info directly into mysql.

But what's ID='3' ?

And why when the bottom one is entered into mysql, the password is encrypted?

I'm trying to replicate the bottom line entry, but instead via a php form, with the same password encryption, possible?

All my attempts so far to enter an encrypted password via a php form have failed :(

 

Any input helpful, thanks!

Link to comment
Share on other sites

In your first example, the SET is really just like the VALUES, so you are setting the 3 columns with the values after the = sign.  So you are setting the ID of that row to 3 in your first example.  If your ID field is auto_increment, then you wouldn't need to set a ID value since the auto would take care of that for you.  Now if you already had a ID of 3 somewhere, you would need to use UPDATE to change the fields data instead of INSERT.

 

MySQL has its own Password hasher, and yes, it's called PASSWORD which you show above.  But I would highly recommend you don't use that and use SHA1 instead (or even MD5).

 

In your 2nd post, try it and see.

Link to comment
Share on other sites

Between:

INSERT INTO tbl_auth_user SET user_id='$user_id', user_password='$user_password' , ID = '3'

 

and:

INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('user', PASSWORD('password'))

 

I don't think the first example would work because you use the 'SET' keyword to update a table rather then to insert something into a table.

UPDATE tbl_auth_user SET user_id='$user_id', user_password='$user_password' WHERE ID = '3'

You code would work, but since you dont have a WHEREclause, it is going to update every row in your tbl_auth_user table. Which isn't a good idea

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.