<?php
require "config.php";
/*
CREATE TABLE `addnews` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`auther` VARCHAR( 255 ) NOT NULL ,
`title` VARCHAR( 255 ) NOT NULL ,
`content` LONGTEXT NOT NULL
) ENGINE = MYISAM ;
*/
$a = $_POST['author'];
$t = $_POST['title'];
$c = $_POST['content'];
if(isset($_POST["add"]) and $_POST["add"] == "news"){
$insert = mysql_query('INSERT INTO addnews
(author,title,content)
VALUES
("$a","$t","$c")') or die("error");
if (isset($insert )){
echo "<h3>Done</h3>";
}
};
echo "
<form action='".$_SERVER['PHP_SELF']."' method='post'>
Author : <input type='text' name='author' /><br>
Title : <input type='text' name='title' /><br>
Content : <textarea name='content'></textarea>
<input type='submit' value='Add news' />
<input type='hidden' name='add' value='news' />
</form>
";
mysql_close($connectdb);
?>
我想从这个判断中得到错误
if(isset($_POST["add"]) and $_POST["add"] == "news"){
$insert = mysql_query('INSERT INTO addnews
(author,title,content)
VALUES
("$a","$t","$c")') or die("error happend while trying to add information to database");
if (isset($insert )){
echo "<h3>Done</h3>";
}
};
并且config.php文件没有问题(连接到数据库的文件) 我正在使用phpmyadmin
答案 0 :(得分:0)
使用&amp;&amp;而不是实际的词和:
if(isset($_POST["add"]) && $_POST["add"] == "news"){
$insert = mysql_query("INSERT INTO addnews
(author,title,content)
VALUES
('$a','$t','$c')") or die("error happend while trying to add information to database");
if (isset($insert )){
echo "<h3>Done</h3>";
}
};
答案 1 :(得分:0)
在这里试试这个
if(isset($_POST["add"]) and $_POST["add"] == "news"){
$insert = mysql_query('INSERT INTO addnews
(author,title,content)
VALUES
("'. $a .'","'. $t .'","'. $c .'")') or die("error happend while trying to add information to database");
if (isset($insert )){
echo "<h3>Done</h3>";
}
};
使用"'. $a .'"
代替"$a"
。
答案 2 :(得分:0)
我认为查询语句错误, 单引号内的双引号在php中无效。 因此,您将更改查询中的引号,如下面的代码
$insert = mysql_query("INSERT INTO addnews
(author,title,content)
VALUES
('$a','$t','$c')") or die("error");
试试这个......: - )
答案 3 :(得分:0)
请在代码中进行更正,如下所示:
$insert = mysql_query("INSERT INTO addnews
(author,title,content)
VALUES
('$a','$t','$c')") or die(mysql_error($link));//Where $link mysql resource object
您将得到Mysql未插入数据的答案。
答案 4 :(得分:0)