webForumDet fria alternativet

insert problem

PHP

3 svar · 184 visningar · startad av matthew

Medlem sedan okt. 2001166 inlägg
Frågan#1

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

Medlem sedan mars 2001593 inlägg
#2
$sql = "INSERT INTO(headline, preamble, text, publishingdate, author) VALUES('$headline', '$preamble', '$text', '$publishingdate'), '$author')";

funkar kanske bättre

Medlem sedan aug. 20002 975 inlägg
#3

INSERT INTO tabellnamn(headline, ...

Medlem sedan okt. 2001166 inlägg
#4

självklart, tack!

254 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849
127 ms — deklarationer (db)
0 ms — hämta statistik (cache)
125 ms — hämta tråd, inlägg och bilagor (db)
127 ms — ändringar (db)