Page 1 of 1

IF exists error

Posted: Tue Sep 14, 2010 9:26 am
by Darkmantle
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

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();
?>

Re: IF exists error

Posted: Tue Sep 14, 2010 12:24 pm
by Gargoyle
activate error messages.

Code: Select all

$finduser="SELECT CitID FROM military WHERE CitID = '$_Post[ID]'";
$_Post[ID] is NOT the same as $_POST[ID].