Php 正在验证记录存在的数据库条件

Php 正在验证记录存在的数据库条件,php,mysql,sql,database,Php,Mysql,Sql,Database,在我的网站上, 我有文本框,用户在其中输入URL Onece用户输入后,我将显示该url的预览,其中包含该url上的图像和小说明 我从数据库中获取预览详细信息 场景如下: 1. user enters url 2. Check whether url exist in table 3. If yes dont inset into db and fetch details like url title, desc, image 4. If not exist insert into table

在我的网站上, 我有
文本框
,用户在其中输入URL

Onece用户输入后,我将显示该url的预览,其中包含该url上的图像和小说明

我从数据库中获取预览详细信息

场景如下:

1. user enters url
2. Check whether url exist in table
3. If yes dont inset into db and fetch details like url title, desc, image
4. If not exist insert into table and then show the preview from it
那个么,我如何首先检查它是否存在于表中呢

我有
$url
来检查条件

select url from post_record where url='".$url."';
我需要此查询的布尔或1/0结果。我怎样才能得到它? 如果为True,则直接获取记录如果结果为0,则首先输入详细信息,然后从表中显示预览

这是正确的方法还是更好的方案。只需选择以下选项:

从post_记录中选择COUNT(*),其中url=?
从post\u记录中选择COUNT(*),其中url=
用户输入的值
是否正确

    $result = mysqli_query("SELECT url from post_data where url='".$url."' and id='".$id."'");
        if ($url = @mysqli_fetch_array($result))
        {
            // do nothing
        }
        else
        {
            //insert url details
        }
            //After this fetch data from table to show preview
我可以这样做:
$flag=“从post_数据中选择url,其中url=”“$url.”和id=”“$id.””
。然后根据标志的0或1值执行操作?