0

I am trying to create a cars table in MySQL, here is my code:

<?php

$sql = "CREATE TABLE cars (
    regnr varchar(10),
    make varchar(30),
    yearmodel int,
    mileage int
)";

if (mysqli_query($connection, $sql)) {
    echo '<p>Table created</p>';
} else {
    echo '<p>Failed: check the sql: ';
    echo $sql;
}

?>

But it resulted in an error:

Connection ok
Failed: check the sql: CREATE TABLE cars ( regnr varchar(10), make varchar(30), yearmodel int, mileage int)

How can I make this code works?

Chi Le
  • 19
  • 6

1 Answers1

0

You could try it like this. Replace _DATABASE_ with the name of the database you want to create the table in

$sql = "CREATE TABLE _DATABASE_.cars (
    regnr varchar(10),
    make varchar(30),
    yearmodel int,
    mileage int
)";
Hendrik
  • 167
  • 7