Okay guys, this might be very simple, but i just cant find the answer.
What i want to do is prevent users from submiting entries that already exist in the database using php.
This is the example code i have:
<?php
$mysql = new mysqli('localhost', 'ernesto', 'asdf', 'db') or die('your\'re dead');
$query = "SELECT * FROM myTable WHERE name='asdf'";
$result = $mysql->query($query) or die($mysql->error);
$num = mysql_num_rows($result);
if($num != 0) {
echo 'name already exist';
} else {
echo 'okay';
}
?>
All want is to be sure that if the there is an existing row in name with an entry of 'asdf' (example) then it will echo something like name already exists, but if it doesnt i want it to echo okay. What happens is that it ALWAYS echos okay, in other words it always says there is no row named 'name' with the value of 'asdf'
Thanks in advanced!!!