IF exists error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Darkmantle
Forum Newbie
Posts: 3
Joined: Sun Sep 05, 2010 6:28 am

IF exists error

Post 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();
?>
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: IF exists error

Post 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].
Post Reply