Jump to content
Larry Ullman's Book Forums

Pg 92. - Step #9 - Why Use Concatenate For The Password?


Recommended Posts

For #9, "Add user to the database" part of the code is:

	$q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', ADDDATE(NOW(), INTERVAL 1 MONTH) )";
		$r = mysqli_query($dbc, $q);

I'm wondering why there is concatenating going on:

 '" . password_hash($p, PASSWORD_BCRYPT) . "'

What does this benefit?  Isn't this info just being dumped into the database as a string?

Link to post
Share on other sites

The concatenation is just adding the output of the function to the query. Alternatively, you could call the function before the query, assign the results to a variable, and then use the variable within the query.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...