Well, me again!
Have an other problem with creating an other table. I want to create a Posts table with this code:

<?php
$servername = "localhost";
$dbname = "mydbname";
$dbusername = "mydbusername";
$dbpassword = "mydbpassword";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbusername, $dbpassword);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = 'CREATE TABLE Posts(
    ID INT(128) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    Title CHAR(100),
    Author CHAR(100),
    Content CHAR(100),
    )';

    $conn->exec($sql);
    echo "Table Posts created successfully.<br>";
    }
catch(PDOException $e)
    {
    echo $sql . "<br>" . $e->getMessage();
    }

$conn = null;
?>

But when i type the url of that file in the browser, this error appear on the page:

CREATE TABLE Posts( ID INT(128) UNSIGNED AUTO_INCREMENT PRIMARY KEY, Title CHAR(100), Author CHAR(100), Content CHAR(100), )
SQLSTATE[42000]: Syntax error or access violation: 1064 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 ')' at line 6

I didn't understand what is the syntax error for? The error says at line 6, but line 6 is empty!

OOPSS!! sorry i found the problem.
The problem was here Content CHAR(100), there was no need for ,.

check your coding for

$sql = 'CREATE TABLE Posts(
    ID INT(128) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    Title CHAR(100),
    Author CHAR(100),
    Content CHAR(100),
    )';

should be

$sql = 'CREATE TABLE Posts(
    ID INT(128) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    Title CHAR(100),
    Author CHAR(100),
    Content CHAR(100)
    )';

Don't add comma at the last field

Yes right, thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.