检查表中是否存在结果时出错

So I am building a table session :

session:

session_name | *Text*
session_number | *auto_increment*

I want to check whether there is a session_name result already in the table and if there isn't add it with a unique session_number then create a session with that number and if there is add the session_number to a session:

attempt:

session_start();
ob_start();

if(isset($_POST['enter'])){
    if($_POST['name'] != ""){
        $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
    }
}
$name = ucwords(strtolower($_SESSION['name']));

$method = "SELECT * FROM session WHERE session_name = '$name'";
$resulty = mysql_query($con, $method);
//where $con is the connection to my database
if(mysql_num_rows($resulty) == 0) {
    //not found
     $sql="INSERT INTO session (session_name)

     VALUES

     ('$name')";

}

$result = mysql_query("SELECT * FROM session WHERE session_name = '$name'");

$row = mysql_fetch_row($result);

echo $row[0]; 
echo $row[1]; // not sure which one is the session_number
mysqli_close($con);

First of all I am getting the errors

Warning: mysql_query() expects parameter 1 to be string, object given

Warning: mysql_num_rows() expects parameter 1 to be resource, null given 

How come?


And also how can I then store the session_number to another session?

You have it reversed,the $query is the first parameter, the $con object is the second parameter

$method = "SELECT * FROM session WHERE session_name = '$name'";
$resulty = mysql_query($method, $con);

please upgrade to mysqli_

Your second error is caused by your first.

Your call to mysql_query should look like

$resulty = mysql_query($method);