IF exists error
Posted: Tue Sep 14, 2010 9:26 am
I am trying to do a code that does this. When someone enters the form, it searches the database for CitID ($_POST['CitID']). Then if that particular CitID already exists (primary key) then it diverts to ../adderror.php otherwise it inserts the user and diverts to ../addsuccess.php
But as it stands it constantly diverts to addsuccess.php even if the record already exists. It doesn't even give a duplicate error ;s
But as it stands it constantly diverts to addsuccess.php even if the record already exists. It doesn't even give a duplicate error ;s
Code: Select all
<?php
include('../../connect.php');
include('../../functions.php');
$finduser="SELECT CitID FROM military WHERE CitID = '$_Post[ID]'";
$result=mysql_query($finduser);
$numrows = mysql_num_rows($result);
if($numrows > 0) {
header("location:../adderror.php");
} else {
$insertuser = "INSERT INTO military (CitID, Branch, Regiment, Position) VALUES ('$_POST[ID]','$_POST[Branch]','$_POST[Regiment]','$_POST[Position]')";
mysql_query($insertuser);
updatecitizen($_POST[ID]);
header("location:../addsuccess.php");
}
mysql_close();
?>