检查我的数据库表中是否存在值

I want to check if a URL exists in my MySQL database table for example if Url=exist, message=url already exist

<?php
if(isset($_POST['Submit'])){
    $dbhost = 'localhost';
    $dbuser = '####';
    $dbpass = '#######';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    $Title = $_POST['Title'];
    $Url = $_POST['Url'];
    $email_data = $_POST['email_data'];
    $type_data = $_POST['type_data'];
    $sql = "INSERT INTO table ". "(Title,Url,email_data,type_data)"."VALUES('$Title','$Url','$email_data','$type_data')";
    mysql_select_db('dbname');
    $retval = mysql_query( $sql, $conn );
        if(! $retval ){
            die('Could not enter data: ' . mysql_error());
        }
    echo "<script type='text/javascript'>alert('submitted successfully!')</script>";
    mysql_close($conn);
} else {
?>

You can do like this

$sql = "SELECT Url FROM 'your_table_name' WHERE Url = $_POST['Url']";

Run this sql and if it is return true you can say its exist.

Its a bit hard know what you are doing by just looking at the code but if you wondering how to check if something is in the database you could do like this:

PHP:

$sql = mysql_query("SELECT * FROM dbname WHERE Url='$Url'");
if(mysql_num_rows($sql) > 0){
    echo "alreday exist";
}
$query = mysql_query('select url from table-name where url=$_post['url']');
if(mysql_fetch_rows($query) != 0){
echo "URL allready Exists";
}else{ 
Insert Query 
}

Hi, Try this code.