---
title: "insert problem"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/72934-insert-problem"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "matthew"
published: "2003-04-02T11:39:05.000Z"
updated: "2003-04-02T12:49:37.000Z"
replies: 3
views: 190
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/72934-insert-problem"
---

# insert problem

## #1 — matthew, 2003-04-02T11:39Z

skapar först tabellen :

$sql = 'CREATE TABLE \`news\` (
        \`id\` INT(10) DEFAULT 0 NOT NULL AUTO_INCREMENT,
        \`headline\` VARCHAR( 50 ) NOT NULL,
        \`preamble\` VARCHAR( 50 ) NOT NULL,
        \`text\` TEXT,
        \`publishingdate\` DATETIME NOT NULL,
        \`author\` VARCHAR(50),		
        PRIMARY KEY ( \`id\` )
       )';
echo 'Creating table: \\'news\\'....\<br\>\<br\>';

Blir sedan fel när jag ska lägga in data i news. Så här ser koden ut

$headline = "Overskrift";
$preamble ="Ingress";
$text ="brodtext";
$publishingdate = "2003-03-31 00:00:00";
$author = "jag";

$sql = "INSERT INTO(headline, preamble, text, publishingdate, author) VALUES('$headline', '$preamble', '$text', $publishingdate), '$author')";

print $sql . "\<BR\>\<BR\>";
mysql_select_db("news", $cn);
mysql_query($sql, $cn ) or die(mysql_error());

felmeddelande:
INSERT INTO(headline, preamble, text, publishingdate, author) VALUES('Overskrift', 'Ingress', 'brodtext', NOW(), 'jag')

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 '(headline, preamble, text, publishingdate, author) VALUES('Over

Permalänk: https://www.webforum.nu/p/72934

## #2 — netfeed, 2003-04-02T12:01Z

```php
$sql = "INSERT INTO(headline, preamble, text, publishingdate, author) VALUES('$headline', '$preamble', '$text', '$publishingdate'), '$author')";
```

funkar kanske bättre

Permalänk: https://www.webforum.nu/p/998951

## #3 — Matte, 2003-04-02T12:11Z

INSERT INTO **tabellnamn**(headline, ...

Permalänk: https://www.webforum.nu/p/998964

## #4 — matthew, 2003-04-02T12:49Z

självklart, tack!

Permalänk: https://www.webforum.nu/p/999009

---

Tråden på webben: https://www.webforum.nu/amne/php/72934-insert-problem
