此代码用于检查slug或执行插入操作时是否存在于数据库中的任何值。
<?php
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$slug =$_POST['slug'];
$title =$_POST['title'];
$description= $_POST['description'];
//$created_date=$_POST['created_date'];
// $updated_date = $_POST['updated_date'];
$status = $_POST['status'];
$sql = "INSERT INTO Pages SET slug='$slug', title='$title', description='$description', status='$status'"; // query to insert into database
$result = $con->query($sql);
if ($result->num_rows > 0) { //checking the db table*emphasized text*
$data = $result->fetch_assoc($);
echo "Slug already used"; //duplicate slug is existed.
die;
}
else {
echo "No slug used"; //when no similar slug is used
die;
}
header("Location: pages.php?success=Record added successfully.");
die;
}
?>