我有一个创建函数,它在本地主机上运行良好,但在我的服务器上不起作用。我的意思是,数据库中不存储任何内容,而在localhost上存储。顺便说一句,我使用winhost。这是代码:
public function create ($title, $content, $date, $price){
$db = Dbclass::getDB();
$query = "INSERT INTO upcoming_albums (albums_title, albums_content, albums_date, albums_price, albums_img_path)
VALUES (:title, :content, :date, :price, :path)";
$statement = $db->prepare($query);
$statement->bindParam(':title', $title, PDO::PARAM_STR, 50);
$statement->bindParam(':content', $content);
$statement->bindParam(':date', $date);
$statement->bindParam(':price', $price, PDO::PARAM_STR, 10);
$statement->bindValue(':path', $this->target_path, PDO::PARAM_STR);
$statement->execute();
}
这是我的表格:
<form action="" enctype="multipart/form-data" method="post" id="form_c">
<label for="title">Title:</label>
<input type="text" name="title" id="title"/>
<label for="content">Content:</label>
<textarea name="content" id="content"></textarea>
<label for="date">Release Date (RRRR-MM-DD):</label>
<input type="text" name="date" id="date"/>
<label for="price">Price:</label>
<input type="text" name="price" id="price"/>
<label for="album_img">Price:</label>
<input type="file" name="file" id="album_img"/>
<span>
<?php
if (isset($_POST['btn_submit'])) {
$upcoming_album->uploadImg();
}
?>
</span>
<button type="submit" name="btn_submit">Submit</button>
</form>
这是与设置创建方法的表单相同的文件中的代码:
<?php
require_once "../../controllers/admin/Album.php";
$upcoming_album = new Album;
if (isset($_POST['btn_submit'])) {
$upcoming_album->setFile();
$upcoming_album->create($_POST['title'],$_POST['content'],$_POST['date'],$_POST['price']);
}
$albums = $upcoming_album->read();
?>
更新方法也不起作用。然而,delete方法就像一个符咒。CRUD操作在本地主机中运行得很好。
好的!。但在您看来,PHP crud在本地服务器上运行良好,但在服务器上则不然。问题可能是一些问题,如:-
- 您正在使用PDO在数据库中插入值(即,您在本地主机上启用了扩展)。所以它运行良好。但它可能不会在服务器中启用。因此,请尝试在您的PHP配置中启用
-
或者你可以检查这条线$db=Dbclass::getDB();是否激活数据库
echo";print_r($db);出口