Mini Shell

Direktori : /home/haworld/public_html/admin/
Upload File :
Current File : /home/haworld/public_html/admin/testimonial-add.php

<!DOCTYPE html>
<html lang="en">

<head>
    <?php include('include/head_admin.php');

    $page_id = '17';

    $image = '';
    $image_alt_tag = '';
    $name = '';
    $comment = '';
    $state = '';

    if (isset($_GET['id']) && $_GET['id'] != '') {
        $id = get_safe_value($con, $_GET['id']);
        $image_required = '';
        $res = mysqli_query($con, "select * from testimonial where id='$id'");
        $check = mysqli_num_rows($res);
        if ($check > 0) {
            $row = mysqli_fetch_assoc($res);
            $image = $row['image'];
            $image_alt_tag = $row['image_alt_tag'];
            $name = $row['name'];
            $comment = $row['comment'];
            $state = $row['state'];
        } else {
            header('location:testimonial-all.php');
            die();
        }
    }

    if (isset($_POST['submit_testimonial'])) {
        // prx($_POST);
        $image_alt_tag = get_safe_value($con, $_POST['image_alt_tag']);
        $name = get_safe_value($con, $_POST['name']);
        $comment = get_safe_value($con, $_POST['comment']);
        $state = get_safe_value($con, $_POST['state']);

        if (isset($_GET['id']) && $_GET['id'] == 0) {
            if ($_FILES['image']['type'] != 'image/png' && $_FILES['image']['type'] != 'image/jpg' && $_FILES['image']['type'] != 'image/jpeg' && $_FILES['image']['type'] != 'image/webp') {
                $msg = "Please select only png, jpg, webp and jpeg image format";
            }
        } else {
            if ($_FILES['image']['type'] != '') {
                if ($_FILES['image']['type'] != 'image/png' && $_FILES['image']['type'] != 'image/jpg' && $_FILES['image']['type'] != 'image/jpeg' && $_FILES['image']['type'] != 'image/jpeg') {
                    $msg = "Please select only png, jpg, webp and jpeg image format";
                }
            }
        }

        $msg = "";

        if ($msg == '') {
            if (isset($_GET['id']) && $_GET['id'] != '') {
                if ($_FILES['image']['name'] != '') {
                    $image =  $_FILES['image']['name'];
                    move_uploaded_file($_FILES['image']['tmp_name'], "../media/testimonial/" . $image);
                    mysqli_query($con, "UPDATE `testimonial` SET  `name`='$name',`comment`='$comment',`state`='$state',`image`='$image',`image_alt_tag`='$image_alt_tag'  WHERE `id`='$id'");
                } else {
                    $update_query = "UPDATE `testimonial` SET `name`='$name',`comment`='$comment',`state`='$state',`image`='$image',`image_alt_tag`='$image_alt_tag' WHERE `id`='$id'";

                    mysqli_query($con, $update_query);
                }
            } else {
                $image = rand(111111111, 999999999) . '_' . $_FILES['image']['name'];
                move_uploaded_file($_FILES['image']['tmp_name'], "../media/testimonial/" . $image);
                $insert_query = "INSERT INTO `testimonial` (`name`,`comment`,`state`,`image`, `image_alt_tag`)
                VALUES ('$name','$comment','$state','$image', '$image_alt_tag')";
                mysqli_query($con, $insert_query);
                print_r($insert_query);
            }

            header('location:testimonial-all.php');
            die();
        }
    }

    ?>
</head>

<body>
    <!--== MAIN CONTRAINER ==-->
    <?php include('include/header_admin.php'); ?>

    <!--== BODY CONTNAINER ==-->
    <div class="container-fluid sb2">
        <div class="row">

            <?php include('include/sidebar_admin.php'); ?>

            <div class="sb2-2">
                <div class="sb2-2-2">
                    <ul>
                        <li><a href="index.php"><i class="fa fa-home" aria-hidden="true"></i> Home</a>
                        </li>

                        <!-- <li class="page-back"><a href="index.php"><i class="fa fa-backward" aria-hidden="true"></i> Back</a>
                        </li> -->
                    </ul>
                </div>
                <div class="sb2-2-add-testimonial sb2-2-1">
                    <div class="box-inn-sp">
                        <div class="bor">
                            <form method="post" enctype="multipart/form-data">
                                <div class="row">
                                    <div class="input-field col s12">
                                        <input id="name" type="text" name="name" class="validate" value="<?php echo $name ?>" required>
                                        <label for="name">Name</label>
                                    </div>
                                    <div class="input-field col s12">
                                        <input id="comment" type="text" name="comment" class="validate" value="<?php echo $comment ?>" required>
                                        <label for="comment">Comment</label>
                                    </div>
                                    <!-- <div class="input-field col s12">
                                        <input id="state" type="text" name="state" class="validate" value="<?php echo $state ?>" required>
                                        <label for="state">State</label>
                                    </div> -->
                                    <!-- <div class="input-field col s12">
                                        <div class="file-field">
                                            <div class="btn">
                                                <span>File</span>
                                                <input type="file" name="image" value="<?php echo $image ?>">
                                            </div>
                                            <div class="file-path-wrapper">
                                                <input class="file-path validate" type="text" name="image" placeholder="Upload testimonial Image" value="<?php echo $image ?>">
                                            </div>
                                        </div>
                                        <?php
                                        if ($image != '') {
                                            echo "<a target='_blank' href='" . "../media/testimonial/" . $image . "'><img width='150px' src='" . "../media/testimonial/" . $image . "'/></a>";
                                        }
                                        ?>
                                    </div>
                                    <div class="input-field col s12">
                                        <input id="image_alt_tag" type="text" name="image_alt_tag" class="validate" value="<?php echo $image_alt_tag ?>" required>
                                        <label for="image_alt_tag">Image Alt Text</label>
                                    </div> -->


                                </div>
                                <div class="row">
                                    <div class="input-field col s12">
                                        <input type="submit" name="submit_testimonial" class="waves-effect waves-light btn-large" value="Submit">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <?php include('include/footer_admin.php'); ?>

    <?php include('include/foot_admin.php'); ?>


</body>

</html>