WHERE
を使用する 指定されたユーザー名の行のみを取得する句:
"SELECT * FROM user_list WHERE uname='".$server->real_escape_string($uname)."'"
次に、クエリの結果、 MySQLi_Result::num_rows
:
function createUser($uname,$pword) {
$server->connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$result = $server->query("SELECT * FROM user_list WHERE uname='".$server->real_escape_string($uname)."'");
if ($result->num_rows() === 0) {
if ($server->query("INSERT INTO user_list (uname) VALUES ('".$server->real_escape_string($uname)."'")) {
echo "User added Successfully";
} else {
echo "Error while adding user!";
}
} else {
echo "User already exists!";
}
}