所以我无法连接或插入数据到我的数据库中。我正在使用表单来收集我需要的信息。然后我尝试插入到我的数据库中。我不确定问题是什么,但我认为我在连接时遇到了问题。我正在使用两个文件来尝试完成此操作。
addQuite.html文件
AddQuoteAdd a Quote
Quote:
Author:
这是我的index.php文件,这是我试图连接并插入到我的数据库
QuotesQuotes
//connet to server
$db = new PDO("mysql:host=server;dbname=quotes", "root" , "");
//check connections
if($db===false){
die("ERROR: Could not connect. ");
}
//get name and quote
$name = $_GET['author'];
$quote = $_GET['quote'];
//attemp insert query execution
$sql = "INSERT INTO quotations (name, quote, rating ) VALUES
('$name', '$quote', 0)";
?>
博主在尝试通过HTML表单收集信息并将其插入到数据库中遇到困难。他们使用PHP的PDO来连接到一个名为'quotes'的数据库,但似乎连接或插入操作失败。在index.php文件中,他们获取了表单的'author'和'quote'字段,并尝试执行SQL插入语句,但未成功。问题可能出在数据库连接上。
1084

被折叠的 条评论
为什么被折叠?



