在PHP中比较数据库中的数据

What I'm trying to do is saving some data in the database and when user will press "SAVE" button script will compare the data entered by the user with data already present in the database. If the data matches it will show a warning that is "The entered data is already in the database please use search bar to search it." In my case I only want it to check phone number and cnic (cnic = national identity card number). Here is what I am doing.

 <?php include_once("config.php"); // mysql_connect and database selection are in this file.
    $name = $_POST['name']; // data coming from save_info.php
    $gender = $_POST['option']; // data coming from save_info.php
    $cnic = $_POST['cnic']; // data coming from save_info.php
    $number = $_POST['number']; // data coming from save_info.php
    $address = $_POST['address']; // data coming from save_info.php
    $info = $_POST['info']; // data coming from save_info.php
    $check = "SELECT * FROM info WHERE num = $number AND cnic = $cnic"; // checking data
    $cresult = mysql_query($check);
    if (mysql_num_rows($cresult)==1) {
         echo "The entered phone number/cnic is already in the database, Please use search bar to search it.";
        header('refresh:10;url=save_info.php');
        }
        else
        {

    $sql = "INSERT INTO info(name, gender, cnic, num, address, info)VALUES('$name', '$gender', '$cnic', '$number', '$address', '$info')";
    $result = mysql_query($sql);
    mysql_close();
    header('Location:saved_info.php');
    }
?>

You probably missed the quotes in your query:

$check = "SELECT * FROM info WHERE num = \"$number\" AND cnic = \"$cnic\"";

Since the fields are probably textual (varchar or something like that) you need to tell where the limits of the values you're comparing to are.

Also if you need to skip the saving if any of the values matches you should use OR:

$check = "SELECT * FROM info WHERE num = \"$number\" OR cnic = \"$cnic\"";

Try to add single quotes around your parameters and rewrite the query like this..

$check = "SELECT * FROM `info` WHERE `num` = '$number' OR cnic='$cnic'";

Also, on your if statement.. check like this

if (mysql_num_rows($cresult)>0) {

Also, stop using mysql_* functions as they are deprecated. Switch to MySQLi or PDO instead.