I think you're getting a little mixed up on the difference between single an double quotes in PHP.
First off, if you start off string quoting with one, you can use the other inside, like this:
$string = "this is a string with a ' mark in it";
Note that we have a single quote in there. That won't work if we do it like this:
$string = 'another string with ' in it';
Note that now the string will end after the word will and create an error. We can do the opposite, like s:
$string = 'a string with " in it';
Now, further, a string created with " " marks will interpret strings inside of it as well as the meta characters like \n for a cariage return, while a string created with ' ' marks won't. So, we get something like this:
$pet = "dog";
print "A $pet makes a nice companion\n";
A dog makes a nice companion
print 'A $pet makes a nice companion\n';
A $pet makes a niec companion\n
So, what you need to do is just enclose your string in " marks and go:
$query = "CREATE TABLE $username (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL, PRIMARY KEY(id))";