PHP PDO添加到数据库将不起作用?[日历]
我找到了一个日历脚本,就像我的其他文件一样,我希望它们运行一个config.php文件。到目前为止,每一个脚本都是这样的,尽管我发现一个日历脚本是用PHP PDO编码的,其他脚本都是用相同的语言编写的,尽管我尝试包含config.PHP,但由于某些原因它无法工作 脚本的原始代码:[有效]PHP PDO添加到数据库将不起作用?[日历],php,pdo,calendar,Php,Pdo,Calendar,我找到了一个日历脚本,就像我的其他文件一样,我希望它们运行一个config.php文件。到目前为止,每一个脚本都是这样的,尽管我发现一个日历脚本是用PHP PDO编码的,其他脚本都是用相同的语言编写的,尽管我尝试包含config.PHP,但由于某些原因它无法工作 脚本的原始代码:[有效] <?php $id = $_POST['id']; $title = $_POST['title']; $start = $_POST['start']; $end = $
<?php
$id = $_POST['id'];
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
try {
$bdd = new PDO('mysql:host=localhost;dbname=database2', 'root', 'mypassword');
} catch(Exception $e) {
exit('Unable to connect to database.');
}
// update the records
$sql = "UPDATE evenement SET title=?, start=?, end=? WHERE id=?";
$q = $dbh->prepare($sql);
$q->execu
te(array($title,$start,$end,$id));
?>
我对脚本的编辑:
<?php
include "../inc/config.php";
$id = $_POST['id'];
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
// update the records
$sql = "UPDATE evenement SET title=?, start=?, end=? WHERE id=?";
$q = $dbh->prepare($sql);
$q->execute(array($title,$start,$end,$id));
?>
Config.php
<?php
$hostname = 'localhost';
$username = 'root';
$password = 'mypassword';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=database2", $username, $password);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
请详细说明。你是什么意思?你说我不会工作吗?它会抛出任何错误吗?@Bjoern没有错误,但是当我在google chrome上访问开发者工具网络时,我发现了这样一个问题:当代码被执行时,你的错误日志会说什么?include路径正确吗(可能您没有包括该文件)?执行它时,我什么也没有得到。是的,包含路径正确。您是否尝试验证POST数据是否有效?