Nó ko insert dữ liệu đc
<?php
$title = 'Chủ Đề Mới - Kết Bạn';
include 'inc/head.php';
date_default_timezone_set('Asia/Ho_Chi_Minh');
$time = date('d/m/Y h:i:s A');
?>
<?php
if (!isset($_SESSION['username'])){
echo '<div class="phdr"><a href="/ket-ban" style="color:white;">Kết Bạn</a> › Chủ Đề Mới</div><div class="list">Vui lòng đăng nhập để thực hiện chức năng !</div>';
exit;
}
?>
<div class="phdr">Chủ Đề Mới</div>
<?php
$server_username = "ltm_20586840";
$server_password = "kunvn04";
$server_host = "sql300.ultimatefreehost.in";
$database = 'ltm_20586840_vina4u';
$conn = mysqli_connect($server_host,$server_username,$server_password,$database) or die("không thể kết nối tới database");
if (isset($_POST["btn_submit"])){
//lấy thông tin từ các form bằng phương thức POST
$title = $_POST["title"];
$content = $_POST["content"];
$tk = $_POST['tk'];
include 'function.php';
$link = rwurl($title);
//Kiểm tra điều kiện bắt buộc đối với các field không được bỏ trống
if ($title == "" || $content == "" || $tk == '' || $time == '') {
echo '<div class="list"><li>Vui lòng nhập đầy đủ thông tin !</li></div>';
}
else {
// Kiểm tra tài khoản đã tồn tại chưa
$sql="select * from ketban where title= '$title'";
$kt=mysqli_query($conn, $sql);
if (mysqli_num_rows($kt) > 0){
echo '<div class="list"><li>Chủ đề đã tồn tại !</li></div><div class="list"><form action="" method="post">
Tiêu đề:<br><input type="text" name="title"><br>Nội dung:<br><textarea name="content"></textara><br><input type="hidden" name="tk" value="'.$_SESSION['username'].'"><input type="hidden" name="time" value="<?php echo ''.$time.''; ?>"><br><input type="submit" name="btn_submit" value="Đăng">
</div>
</form>';
include 'inc/foot.php';
die();
}
if ($tk != $tk){
echo '<div class="list"><li>Đã có lỗi xảy ra !</li></div>';
}
else {
//thực hiện việc lưu trữ dữ liệu vào db
$sql = "INSERT INTO ketban (title, content, tk, link, time) VALUES ('$title','$content','$tk','$link','$time')";
// thực thi câu $sql với biến conn lấy từ file connection.php
mysqli_query($conn,$sql);
echo '<div class="list"><li>Đăng bài thành công !</li></div>';
}
}
}
?>
<div class="list"><form action="" method="post">
Tiêu đề:<br><input type="text" name="title"><br>Nội dung:<br><textarea name="content"></textarea><input type="hidden" name="tk" value="'.$_SESSION['username'].'"><input type="hidden" name="time" value="<?php echo ''.$time.''; ?>"><br><input type="submit" name="btn_submit" value="Đăng">
</div>
</form>
<?php
include 'inc/foot.php';
?>