php and mysql queries

Good afternoon! There was such question how to implement request. There are tables with users and objects, you need to make sure that when you query, it checks if there is a user in the database. If it is, then display a list of items it has, and if not, then add it to the database. How can I do this correctly?


Answer 1, authority 100%

$result = mysql_query ("SELECT * FROM 'users' WHERE 'name'='$username' ");
if (mysql_num_rows($result)) {
 while($row = mysql_fetch_array($result))
  {
  echo $row['items'] . "<br>";
  }
} else {
 mysql_query("INSERT INTO 'users' (name, items) VALUES ('ololol', 'trololo')");
}

Answer 2

$q=mysql_query(“select * from <table> where <What do you want>=Search>”);

<> – remove from the request.