想要更新以逗号分隔的字符串

时间:2015-04-13 20:15:59

标签: php mysql content-management-system

我想制作能够更新文章的CMS。当我使用更新页面时,我收到以下错误:

  

注意:未定义的变量:第105行的C:\ xampp \ htdocs \ website \ admin \ edit_posts.php中的post_image

这是我的代码:

 <?php 
session_start();

if(!isset($_SESSION['user_name'])){

header("location: ../login.php");
}
else {

?>

<html>
    <head>
        <title>Admin Panel</title>

    <link rel="stylesheet" href="../apearance/stylesheet.css" />
    </head>

<body>

<div id="navbar">
<div id="logo"><img id="logo"  src="../apearance/logo.png" height="27px"></div>

<a id="button" href="view_posts.php">View Posts</a>
<a id="button" href="index.php?insert=insert">Insert New Post</a>
<a id="button" href="#">View Comments</a>
<a id="button" href="#">Webshop</a>
<a id="button" href="#">Do do list</a>
<a id="button" href="logout.php"><span style="color:red">Logout</span></a>
<br><hr>
</div>

<?php
include("includes/connect.php");
if(isset($_GET['edit'])){

    $edit_id = $_GET['edit'];
    $edit_query = "select * from posts where post_id = '$edit_id' ";

    $run_edit = mysql_query($edit_query);

    while ($edit_row = mysql_fetch_array($run_edit)){

        $post_id = $edit_row['post_id'];
        $post_title = $edit_row['post_title'];
        $post_category = $edit_row['post_category'];
        $post_header_image = $edit_row['post_header_image'];
        $post_image = $edit_row['post_image'];
        $post_content = $edit_row['post_content'];
        $post_content2 = $edit_row['post_content2'];
        $post_video = $edit_row['post_video'];
}}
?>

<div id="tile" height="100px">
<form method="post" action="edit_posts.php?edit_form=<?php $post_id; ?>" enctype="multipart/form-data">

    <table align="center" border="0">

        <tr>
            <td align="center" colspan="2"><h1>Edit Post Here</h1></td>
        </tr>

        <tr>
            <td align="left">Post Title:</td>
            <td><input value="<?php echo $post_title; ?>" type="text" name="title" size="30"></td>
        </tr>

        <tr>
            <td align="left">Post Category:</td>
            <td><input value="<?php echo $post_category; ?>" type="text" name="category" size="30"></td>
        </tr>

        <tr>
            <td align="left">Post header Images:</td>

            <td>
            <input type="file" name="header_image">
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
            <img src="../images/<?php echo $post_header_image; ?>" height="100" >
            </td>
        </tr>


        <tr>
            <td align="left">Post Content:</td>
            <td><textarea  name="content" cols="30" rows="15"><?php echo $post_content; ?></textarea></td>
        </tr>

        <tr>
            <td align="left">Post Images:</td>
            <td><input type="file" name="files[]" multiple>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
            <?php
            $values = explode(',', $post_image);
            if( count($values)){
                foreach($values as $value){

                    echo "<img src=\"../images/".$value."\" height=\"100\">";
                }
            }
            ?>
            </td>
        </tr>

        <tr>
            <td align="left">Post Content2:</td>
            <td><textarea name="content2" cols="30" rows="15"><?php echo $post_content2; ?></textarea></td>
        </tr>

        <tr>
            <td align="left">Post Video:</td>
            <td><textarea name="video" cols="30" rows="15"><?php echo $post_video; ?></textarea></td>
        </tr>

        <tr>
            <td align="right" colspan="6"><input type="submit" name="submit" value="Update Now"></td>
        </tr>


    </table>
</form>
</div>
</body>
</html>



<?php

    if(isset($_POST['update'])){

        $update_id = $_GET['edit_form'];
        $post_title1 = $_POST['title'];
        $post_date1 = date('m-d-y');
        $post_category1 = $_POST['category'];
        $post_content1 = $_POST['content'];
        $post_content21 = $_POST['content2'];
        $post_video1 = $_POST['video'];
        $post_header_image1= $_FILES['header_image']['name'];
        $header_image_tmp= $_FILES['header_image']['tmp_name'];

        $filenames = array_values($_FILES['files']['name']);    
        $post_image1 = rtrim(implode(',', $filenames), ',');

        if($post_title1=='' or $post_category1=='' or $post_content1=='' or $post_header_image1==''){

        echo "<script>alert('Any of the fields is empty')</script>";
        exit();
        }

        else {

         move_uploaded_file($header_image_tmp,"../images/$post_image1");

            $update_query = "update posts set post_title='$post_title1',post_date='$post_date1',post_category='$post_category1',post_header_image='$post_header_image1',post_image='$post_image1',post_content='$post_content1',post_content2='$post_content21',post_video='$post_video1' where post_id='$update_id'";

            if(mysql_query($update_query)){

            echo "<script>alert('Post has been updated')</script>";

            echo "<script>window.open('view_posts.php','_self')</script>";

            }

        }
    }



?>

<?php }?>

非常感谢任何帮助。

0 个答案:

没有答案