Why not fire the SQL query?

Hello! There is a simple script that creates a database with the specified name, but for some reason
<?php
$create = $_POST['name'];
$link = mysqli_connect("localhost", "create", "****");

if (!$link) {
 echo "Error: unable to connect to MySQL." . PHP_EOL;
 echo "error Code errno:" . mysqli_connect_errno() . PHP_EOL;
 echo "error Text error:" . mysqli_connect_error() . PHP_EOL;
exit;
}

echo "MySQL Connection established!" . PHP_EOL;
echo "<br-->server Information: ". mysqli_get_host_info($link) . PHP_EOL;
if (isset ($create)) {
$crquery = mysqli_query ($link, "CREATE DATABASE $db");
echo "<br>Database created successfully";
}
mysqli_close($link);
?>
<form method="post">
 the <br>database Name
 br><input type="text" name="name">
 <input type="submit" name="Save" value="Create DB">
</form>

Displaying PHP errors is enabled, no errors, but database is still not created. Why?
July 2nd 19 at 13:25
4 answers
July 2nd 19 at 13:27
Solution
CREATE DATABASE $db
$db what is?
Fixed, but the database still not created - Glennie_Beie commented on July 2nd 19 at 13:30
: the answer marked correct ))))) - Lelah.Friesen59 commented on July 2nd 19 at 13:33
July 2nd 19 at 13:29
Run the query from the same user without this script. In phpMyAdmin, or in the console client MySQL or connect to the server remotely... Then we'll know whether it's in the script, or the problem is that the user under which You are working in a database - not enough rights to create the database. In General, after request, to create a database - you need to check again the error...
July 2nd 19 at 13:31
You catch the name of the database which should be created here $create = $_POST['name'];
When creating a use other variable "CREATE DATABASE $db"
Replace $db $create. Or Vice versa. This time.
Two - don't forget about input validation on $_POST.
July 2nd 19 at 13:33
but if: php.net/manual/ru/mysqli.error.php
...
$crquery = mysqli_query ($link, "CREATE DATABASE $db");
if ( $crquery === false ){
 echo mysqli_error($link);
}

Find more questions by tags PHP