检查数据库中的特定条目

I want to check whether a specific entry is present in my database or not. If present then condition,if not then condition. I tried this code but got errors

<?php
$con=mysqli_connect("localhost","root","","student");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$classname = mysqli_real_escape_string($con, $_POST['class']);

$result = mysql_query("SELECT * FROM subjectinfo WHERE class = '{$classname}'", $con);

if(mysql_num_rows($result) == 0)
    {
    echo "No Such Entry In Table. Please ADD it First.";

    }
    else
    {
    echo "Entry Available";
    }       
}
mysqli_close($con);
?> 

Errors :

Warning: mysql_query() expects parameter 2 to be resource, object given in C:\xampp\htdocs\pages\test.php on line 11

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\pages\test.php on line 13 No Such Entry In Table. Please ADD it First.

Like your comments. Make sure you don't mix up mysqli and mysql. mysql is deprecated so you're better off using mysqli.

$con=mysqli_connect("localhost","root","","student");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$classname = mysqli_real_escape_string($con, $_POST['class']);

$result = mysqli_query($con, "SELECT * FROM subjectinfo WHERE class = '{$classname}'");

if(mysqli_num_rows($result) == 0)
    {
    echo "No Such Entry In Table. Please ADD it First.";

    }
    else
    {
    echo "Entry Available";
    }       
}
mysqli_close($con);
?> 

</div>

You are mixing MySQL APIs - mysql_ + mysqli_ they do not mix together. Plus, your DB connection's backwards in your query. The connection comes first.

Here:

<?php
$con=mysqli_connect("localhost","root","","student");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$classname = mysqli_real_escape_string($con, $_POST['class']);

$result = mysqli_query($con,"SELECT * FROM subjectinfo WHERE class = '{$classname}'");

if(mysqli_num_rows($result) == 0)
    {
    echo "No Such Entry In Table. Please ADD it First.";

    }
    else
    {
    echo "Entry Available";
    }       
}
mysqli_close($con);
?> 

Also use or die(mysqli_error($con)) to mysqli_query()

Plus, add error reporting to the top of your file(s) which will help during production testing.

error_reporting(E_ALL);
ini_set('display_errors', 1);

Look into using prepared statements, or PDO with prepared statements, they're safer.


An insight:

Make sure your form element is indeed named.

I.e.:

<input type="text" name="class">

otherwise, you will receive an Undefined index class... warning.