-1

I am new in this field, I am trying to get some skills to be a web developer, kind of. This is the error I get when opening the file in my browser:

Parse error: syntax error, unexpected end of file on line 26.

this is the code:

<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";



$conn = new mysqli($servername, $username, $password, $dbname);

if ($mysqli->connect_error) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}

$sql = "CREATE TABLE MyColor (
color
)";

if ($conn->query($sql) === TRUE) {
echo "Table MyColor created successfully";
} else {
echo "Error creating table: " . $conn->error;


$conn->close()
?>
mdrr5545
  • 29
  • 5

1 Answers1

0

Besides the semicolon is missing from the $conn->close() line, you're SQL statement for the create table is wrong. It is missing type for the color attribute.

Create table should be like this:


CREATE TABLE MyColor (
      color TYPEOFTHEFIELD
)

# TYPEOFTHEFIELD can be whatever type, varchar, int, whatever you want. 

Refer to this about the create table command: https://dev.mysql.com/doc/refman/8.0/en/create-table.html