Når jeg prøver at tilføje en nyhed får jeg denne SQL fejl: Der er en fejl i SQL syntaksen nær '.Test.'', ''.Morten.'', ''.08-02/2009.'', ''.r4.'')' på linje 1
- <body bgcolor="#FF0000">
- <?php
- include ("config.php");
-
- $action = $_GET["action"];
-
- if($action == "submitNews") {
-
- $cName = htmlspecialchars(addslashes($_POST["newsName"]));
- $cAuthor = htmlspecialchars(addslashes($_POST["newsAuthor"]));
- $cText = htmlspecialchars(addslashes($_POST["newsText"]));
- $cDate = date("d-m/Y");
-
- if(!empty($cName) && !empty($cAuthor) && !empty($cText)) {
-
- mysql_query("INSERT INTO news (name, author, date, text)VALUES(''.$cName.'', ''.$cAuthor.'', ''.$cDate.'', ''.$cText.'')") or die(mysql_error());
-
- echo "<span style='color: green; font-weight: bold;'>Nyheden ''.$cName.'' er blevet tilføjet!</span>";
-
- } else {
-
- echo "Du skal udfylde alle felter!";
- }
-
-
- } else {
-
-
- echo "<form action='?action=submitNews' method='POST'>";
- echo "<b>Overskrift:</b><br />";
- echo "<input type='text' name='newsName'><br />";
- echo "<b>Forfatter:</b><br />";
- echo "<input type='text' name='newsAuthor'><br />";
- echo "<b>Overskrift:</b><br />";
- echo "<textarea name='newsText' style='width: 400px; height: 120px;'></textarea><br />";
- echo "<input type='submit' value='OK'>";
- echo "</form>";
- }
- ?>
SQL dump:
- CREATE TABLE `news` (
- `id` int(11) NOT NULL auto_increment,
- `name` varchar(30) NOT NULL default "",
- `author` varchar(30) NOT NULL default "",
- `date` varchar(30) NOT NULL default "",
- `text` text NOT NULL,
- PRIMARY KEY (`id`)
- ) AUTO_INCREMENT=1 ;