post.blade.php 3.24 KB
Newer Older
wutthichai's avatar
wutthichai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
@extends('layouts.loin')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="col-md-8 cardshow" style="text-align: center;">
                <div class="card-header ff">Create Post</div>
                <div class="card-body">
                    <form accept-charset="UTF-8" action="{{ route('post.store') }}" method="POST" enctype="multipart/form-data">
                    {{ csrf_field() }}
                        <div class="form-group">
                            <select class="form-control" type="text" id="menu" name="menu" required>
                                <option>กีฬา</option>
                                <option>การ์ตูน</option>
                                <option>ความรัก</option>
                                <option>ไอที</option>
                                <option>การเมือง</option>
                                <option>อาหาร</option>
                                <option>สัตว์</option>
                                <option>เพลง</option>
                                <option>ภาพยนตร์</option>
                            </select>
                        </div>
                        <div class="form-group">
                            @csrf
                            <label class="label ff">Post Title: </label>
                            <input type="text" name="title" class="form-control" maxlength="255" required placeholder="ความยาวไม่เกิน 255 ตัวอักษร"/>
                        </div>
                        <div class="form-group">
                            <label class="label ff">Post Body: </label>
                            <textarea name="body" rows="10" cols="30" class="form-control" maxlength="999999" required placeholder="ความยาวไม่เกิน 999,999 ตัวอักษร"></textarea>
                        </div>
                        <div class="card">
                            <input type="file" name="image" accept="image/*">
                        </div>
                        <br>    
                        <div class="form-group card">
                            <input type="submit" name="submit" class="btn btn-success" />
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else {
    if (isset($_GET['submit'])) {
        $U_ME = $_GET['menu'];
        $U_H = $_GET['title'];
        $U_M = $_GET['body'];
        $sql = "INSERT INTO `posts`  (`category`, `title`, `body`) 
            VALUES ('$U_ME','$U_H','$U_M')";
        if ($conn->query($sql) === true) {
            echo "New record created successfully";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
        $conn->close();
    } else {
        // echo 'กรุณากรอกข้อมูล';
    }
}
?>
@endsection