【发布时间】:2013-02-08 15:14:53
【问题描述】:
我是开发简单内容管理系统的 php 新手,我有一个字段,如菜单、位置、可见、img_des、内容、信息 ID .. 它几乎所有工作正常,现在我需要向其中插入图像字段。我有一个单独的文件用于表单和新页面的创建 现在是以下代码
if (isset($_POST['submit'])) {
$errors = array();
// 入库前清理数据
$information_id = mysql_prep($_GET['info']);
$menu = trim(mysql_prep($_POST['menu'])); // cut out whitespace for menu
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$image = mysql_prep($_POST['image']);
$img_des = mysql_prep($_POST['img_des']);
$content = mysql_prep($_POST['content']);
if(empty($errors)){
$query = "INSERT INTO pages (
menu, position, visible, img_des, content, information_id
) VALUES (
'{$menu}', {$position}, {$visible},'{$img_des}', '{$content}', {$information_id}
)";
if ($result = mysql_query($query, $connection)) {
$message = "The new page was created successfully";
$new_page_id = mysql_insert_id();
redirect_to("content.php?page={$new_page_id}");
} else {
$message = "The page failed to create";
}
?>
在 img_des 之前我想插入图像。我必须使用什么类型,我必须使用什么代码来插入和检索图像。
【问题讨论】:
-
mysql_query 已弃用,请使用 PDO php.net/manual/fr/function.mysql-query.php
标签: php mysql content-management-system phpmyadmin