check if data exists
Posted: Fri Sep 02, 2005 11:18 am
im trying to write a code that connects to my database and checks to see if a value exists. it it does it will display "Player already exists." If it does not exist it will it will display "Player does not exist."
here is my code
for testing perposes im using a static pid rather then a pid that is submited from a form.
my code kind of works...if the pid exists it does display "Player already exists" however if it does not exist, it dosnt display anything, could someone help me as to where i am going wrong?
here is my code
Code: Select all
$pid = "10864580281";
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname, $db);
$result = mysql_query("SELECT * FROM stats WHERE pid=$pid", $db);
while ($row = mysql_fetch_assoc($result)){
if ($pid) {
echo "Player already exists";
}
else
{
echo "Player does not exist";
}
}my code kind of works...if the pid exists it does display "Player already exists" however if it does not exist, it dosnt display anything, could someone help me as to where i am going wrong?