Php提前表格

时间:2017-05-13 16:06:30

标签: php mysql phpmyadmin content-management-system

我正在研究CMS项目并处理将信息添加到mysql中的表单。一切都工作正常,但“textarea”似乎太简单了,即使是tinymce。我正在寻找任何有助于改善“texarea”的建议,例如添加多个图像(我只允许一个)。

谢谢你,请放弃我糟糕的英语 这是我的代码:

    <script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
  <script>tinymce.init({ selector:'textarea' });</script>

<form method="post" action="insert_post.php" enctype="multipart/form-data">

    <table width="800" align="center" border="10">

        <tr>
            <td align="center" bgcolor="yellow" colspan="6"><h1>Insert New Post Here</h1></td>
        </tr>

        <tr>
            <td align="right">Post Title:</td>
            <td><input type="text" name="post_title" size="30"></td>
        </tr>
        <tr>
            <td align="right" bgcolor="#FF6600"><strong>Post Category:</strong></td>
            <td>
            <select name="cat">
                <option>Select a Category</option>
                <?php
                include("includes/connect.php");
                $get_cats = "select * from catelogries";
                $run_cats = mysql_query($get_cats);
                while ($cats_row=mysql_fetch_array($run_cats)){
                    $cat_id=$cats_row['cat_id'];
                    $cat_title=$cats_row['cat_title'];
                    echo "<option value='$cat_id'>$cat_title</option>";
                }
                ?>
                </select>
                </td>

        </tr>
        <tr>
            <td align="right">Post Author:</td>
            <td><input type="text" name="post_author" size="30"></td>
        </tr>

        <tr>
            <td align="right">Post Keywords:</td>
            <td><input type="text" name="post_keywords" size="30"></td>
        </tr>

        <tr>
            <td align="right">Post Image:</td>
            <td><input type="file" name="post_image"></td>
        </tr>

        <tr>
            <td align="right">Post Content:</td>
            <td><textarea name="post_content" cols="30" rows="15"></textarea></td>
        </tr>

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


    </table>
<?php 


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

    $post_title = $_POST['post_title'];
    $post_date = date('m-d-y');
    $post_cat = $_POST['cat'];
    $post_author = $_POST['post_author'];
    $post_keywords = $_POST['post_keywords'];
    $post_content = $_POST['post_content'];
    $post_image= $_FILES['post_image']['name'];
    $post_image_tmp= $_FILES['post_image']['tmp_name'];

    if( $post_title=='' or $post_cat=='null' or 
        $post_author=='' or $post_keywords=='' or 
        $post_content=='' or $post_image=='')
    {
        echo "<script>alert('Any of the fields is empty')</script>";
        exit();
    } else {

        move_uploaded_file($post_image_tmp,"../images/$post_image");

        $insert_posts = "insert into posts 
                            (category_id,post_title,post_date,
                            post_author,post_image,post_keywords,
                            post_content) 
                        values ('$post_cat','$post_title','$post_date',
                                '$post_author','$post_image','$post_keywords',
                                '$post_content')";

        mysql_query($insert_posts);

        echo "<script>alert('post published successfuly')</script>";
        exit();
    }
}
?>

0 个答案:

没有答案