0

I am working on CMS project and dealing with form which is adding information into mysql. Everything is working fine but the "textarea" seems like too simple even with tinymce. I am looking for any advice that help to improve the "texarea" such as add multiple images ( mine is only allowed one).

Thanks you and please abandon my bad English Here is my code:

    <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();
    }
}
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Justin
  • 11
  • 2
  • 1
    And of course! Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly May 13 '17 at 16:14

0 Answers0