0

So I am trying to add users to my server that can login through the mysql_connect(host,username,password) command. I currently have

$str = "CREATE USER '.$name.'@'localhost' IDENTIFIED BY '.$encryption.'"
$query = mysql_query($str);

When I run this on my server with the variables manually plugged in, the query works. When I run this through php it doesn't. Is my formatting incorrect?

2
  • The formatting does not seems to be good and you may also have permission differences. The php user may not have enough permissions to create mysql users. Commented Oct 29, 2013 at 18:25
  • In this scenario I am using the root user. So I have full permission. Commented Oct 29, 2013 at 18:32

1 Answer 1

1

Get rid of those dots . in the query. You are using doubles quotes and not breaking out of them:

$str = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$encryption'";
Sign up to request clarification or add additional context in comments.

1 Comment

Also, if you are actually supplying the hash instead of the plaintext password, you need: IDENTIFIED BY PASSWORD '$encryption'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.