I'll start by saying i'm probably just being really blind to a minor error here. Could someone either spot my error or tell me if there is an easier way to do this check.
I'm playing with a form that when submitted will check to see if 'name' exists already in the database, if it does it executes one piece of code and if it doesn't exist it inserts it into the database.
The bits of code are irrelevant as I they work perfectly fine on thier own, it's just when it checks if the name exists already it pulls up the warning, but if it doesn't exist it seems to be skipping my else chunk.
// connecting
include("db.php");
// checking for existing
$sql = "SELECT name FROM herbal WHERE name=\"$name\"";
$result = mysql_query($sql);
if ($result != false) {
while($data = mysql_fetch_assoc($result)){
echo $data['name'];
if ($data['name'] == "$name") {
echo "<br>its $name. Warning this exists already";
}
else {
// can't seem to get this executed for some reason
echo "<br>It's not there stick it in the database.";
}
}
}
else {
echo mysql_error();
}
Additional info if required, usign PHP 4.3.1.1 and MYSQL 3.23.38 on Apache 1.3.14 under windows XP pro (I think)