<?php
include "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"]) && $_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>
";
if(gettype($connectdb) == "resource") {
mysql_close($connectdb);
}
?>
我是從這個statment得到錯誤,我認爲不能添加任何內容到MySQL數據庫
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>";
}
};
輸出爲:錯誤happend試圖將信息添加到數據庫中並沒有問題config.php文件(連接到 數據庫的文件)我使用的是phpmyadmin
錯誤是什麼? – Andrius
在您的config.php中,您連接到mySQL,選擇數據庫,然後立即關閉與mySQL的連接? –
當依賴第一張圖片是由一個錯誤引起的,你不知道我幾個小時沒有出現解決方案 – user4158643