// sql to create table
$sql = "CREATE TABLE unpw (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
)";
if ($conn->query($sql) === TRUE) {
echo "Table unpw created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
I'm new to both SQL and PHP and have been working on converting some python and C++
code to PHP with an SQL server for a project of mine, and it's throwing an error saying there
"Error creating table: No database selected
" (thank you error handling).
How do I select a database?
I've tried editing it to say:
$sql = "USE myDB;
CREATE TABLE unpw (
Etc, but I get the error:
"Error creating table: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE unpw ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, username' at line 2"
Any help? Thanks.