webForumDet fria alternativet

insert problem

3 svar · 182 visningar · startad av matthew

matthewMedlem sedan okt. 2001166 inlägg
#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

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

funkar kanske bättre

MatteMedlem sedan aug. 20002 975 inlägg
#3

INSERT INTO tabellnamn(headline, ...

matthewMedlem sedan okt. 2001166 inlägg
#4

självklart, tack!

124 ms totalt · 3 externa anrop · v20260731065814-full.0e50b1ef
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
122 ms — hämta tråd, inlägg och bilagor (db)