Hirdetés

Új hozzászólás Aktív témák

  • lanszelot

    addikt

    válasz sztanozs #6026 üzenetére

    Köszönöm szépen a választ.

    Nekem nem működik. Lehet én csinalok valamit rosszul ezért belinkelem a kódodt, és a hibát.
    //Create another table - Main table for shared ID -This table share ID with supplier_groups
    $sql = "CREATE TABLE IF NOT EXISTS suppliers (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    supplier_name TEXT NOT NULL,
    email TEXT)";

    try {
    $connection->exec($sql);
    echo "Table suppliers created successfully";
    } catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
    }
    //Create another table - Secondary table with shared ID - This table got ID from suppliers table
    $sql = "CREATE TABLE IF NOT EXISTS supplier_groups (
    id INTEGER,
    group_name TEXT NOT NULL,
    FOREIGN KEY (id) REFERENCES suppliers (id))";

    try {
    $connection->exec($sql);
    echo "Table supplier_groups created successfully";
    } catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
    }
    // Create (Insert) Data. SQL query to insert data into the "suppliers" table
    $sql = "INSERT INTO suppliers (supplier_name) VALUES ('Obi van Kenobi')";
    $sql2 = "INSERT INTO supplier_groups (group_name) VALUES ('jedi')";

    try {
    $connection->exec($sql);
    $connection->exec($sql2);
    echo "Data inserted successfully";
    } catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
    }

    Hiba: "Error: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: suppliers.group_id"

Új hozzászólás Aktív témák