Jump to content

Unique ID error


bdmovies

Recommended Posts

So, I'm working on a Unique ID system for individual cases that get inputted into a DB. Here's the code, it works the first time I insert something into the DB, but after that everything returns 0 except the current year......

 

<?php
$query = "SELECT * FROM case_information WHERE case_number = '$case_number' AND person_to_be_served = '$person_to_be_served'";
$result = mysql_query($query);
$lastID = mysql_insert_id();
$row = mysql_fetch_assoc($result);
$uniqueID = $row['uniqueID'];

$year = date('Y');
$unique_year = substr("$uniqueID", 0, 4);
$unique_specific = substr("$uniqueID", -5);

echo "The current year is $year <br>";
echo "The Last Internal ID entered is $lastID <br>";
echo "The Unique year is $unique_year <br>";
echo "The Unique Specific is $unique_specific <br>";
echo "The Unique ID is $uniqueID<br><br>";

//If this is the first record
if ($lastID == "1") {
$unique_specific = "00001";
$unique_year = $year;
echo "Success";
}
elseif ($unique_year == $year) {
$unique_specific = $unique_specific +1;
}
elseif ($unique_year > $year) {
$unique_specific = "00001";
$unique_year = $year;
}
//elseif ($unique_year < $year) {
//die("The server's clock needs to be corrected before anything else can be done.\nThis case was not added.\nPlease contact your system administrator.");
//}

$uniqueID = $unique_year . $unique_specific;

echo "The current year is $year <br>";
echo "The Unique year is $unique_year <br>";
echo "The Unique Specific is $unique_specific <br>";
echo "The Unique ID is $uniqueID<br>";

$query = "UPDATE case_information SET uniqueID='$uniqueID' WHERE internalID = '$lastID'";
mysql_query($query) or die(mysql_error());

?>

 

This is what I get after the first time....

 

The current year is 2007
The Last Internal ID entered is 4
The Unique year is 0
The Unique Specific is
The Unique ID is 0

The current year is 2007
The Unique year is 0
The Unique Specific is
The Unique ID is 0

 

Any suggestions?

Link to comment
Share on other sites

Ok, I've got some more info here..... I added an echo at the end of each if statement to see which one was running....here's the code, and it never showed any of my echo's, so I assume there is something wrong with my if's......

 

<?php
//INSERT THE INFORMATION
$query = "INSERT INTO case_information (date_created, date_received, case_number, plaintiff, defendant, county_issued, state_issued, document_type, person_to_be_served, addressone, addresstwo, city, state, zip, client_reference, status, clientID, attorneyID, serverID) VALUES ('$date', '$date_received', '$case_number', '$plaintiff', '$defendant', '$county_issued', '$state_issued', '$document_type', '$person_to_be_served', '$addressone', '$addresstwo', '$city', '$state', '$zip', '$client_reference', '$status', '$row_client[clientID]', '$row_attorney[attorneyID]', '$row_server[serverID]')";
mysql_query($query) or die(mysql_error());

$query = "SELECT * FROM case_information WHERE case_number = '$case_number' AND person_to_be_served = '$person_to_be_served'";
$result = mysql_query($query);
$lastID = mysql_insert_id();
$row = mysql_fetch_assoc($result);
$uniqueID = $row['uniqueID'];

$year = date('Y');
$unique_year = substr("$uniqueID", 0, 4);
$unique_specific = substr("$uniqueID", -5);

echo "The current year is $year <br>";
echo "The Last Internal ID entered is $lastID <br>";
echo "The Unique year is $unique_year <br>";
echo "The Unique Specific is $unique_specific <br>";
echo "The Unique ID is $uniqueID<br><br>";

//If this is the first record
if ($lastID == "1") {
$unique_specific = "00001";
$unique_year = $year;
echo 'Ran $lastID == "1"';
}
elseif ($unique_year == $year) {
$unique_specific = $unique_specific +1;
echo 'Ran $unique_year == $year';
}
elseif ($unique_year > $year) {
$unique_specific = "00001";
$unique_year = $year;
echo 'Ran $unique_specific > $year';
}
//elseif ($unique_year < $year) {
//die("The server's clock needs to be corrected before anything else can be done.\nThis case was not added.\nPlease contact your system administrator.");
//}

$uniqueID = $unique_year . $unique_specific;

echo "The current year is $year <br>";
echo "The Unique year is $unique_year <br>";
echo "The Unique Specific is $unique_specific <br>";
echo "The Unique ID is $uniqueID<br>";

$query = "UPDATE case_information SET uniqueID='$uniqueID' WHERE internalID = '$lastID'";
mysql_query($query) or die(mysql_error());

?>

Link to comment
Share on other sites

Here's the whole source for the page, I think I know what you're saying, this page is included in the index page, which also has an include connect.php so index.php access's the DB, do I need to close the connection after my update?

 

<style type="text/css">
#base_case {
	display:block;
	}

</style>

<?php 
$date = date ('m/d/Y'); 
?>


<br />
<form name="newcase" action=""method="post">

<div id="base_case">
<table style="border:none;">
<tr>
<td valign="top"align="center">

<!-- CLIENT, ATTORNEY, SERVER -->
<table border="0"width="370"class="noborder">
	<tr>
        	<td>
			<fieldset>
			<legend>Client, Attorney, Server Information</legend>
			<table class="noborder">
                	<tr>
                    	<td>Select Client:</td>
					<td><select name="client" id="client"><option>Select..</option>
						<?php
							$query  = "SELECT firmname FROM client_information ORDER BY firmname DESC";
							$result = mysql_query($query);

							while($row = mysql_fetch_array($result, MYSQL_ASSOC))
							{
    								echo "<option name=client>{$row['firmname']}</option>";
							}

						?></select>
					</td>
                    </tr>
				<tr>
        				<td>Select Attorney:</td>
                        <td>
					<select name="attorney"><option>Select..</option>
						<?php
							$query  = "SELECT fullname FROM attorney_information ORDER BY lname DESC";
							$result = mysql_query($query);

							while($row = mysql_fetch_array($result, MYSQL_ASSOC))
							{
    								echo "<option name=client>{$row['fullname']}</option>";
							}

						?></select>
					</td>
                    </tr>
				<tr>
                    	<td>Select Server:</td>
                        <td>
					<select name="server"><option>Select..</option>
						<?php
							$query  = "SELECT fullname FROM server_information ORDER BY lname DESC";
							$result = mysql_query($query);

							while($row = mysql_fetch_array($result, MYSQL_ASSOC))
							{
    								echo "<option name=client>{$row['fullname']}</option>";
							}

						?></select>
					</td>
                    </tr>
			</table>
           		</fieldset>
		</td>
	</tr>
</table>
<!-- END CLIENT, ATTORNEY, SERVER -->

</td><td align="center"valign="top">

<!-- REFERENCE INFORMATION -->
<table class="noborder">
	<tr>
		<td>
			<fieldset><legend>Reference Information</legend>
			<table class="noborder">
				<tr>
					<td>Client Reference:</td>
					<td><input type="text"name="client_reference"onFocus="this.id = 'on'"onBlur="this.id = 'off'"></td>
				</tr>
				<tr>
					<td>Date Created:</td>
					<td><input type="text"name="date_created"onFocus="this.id = 'on'"onBlur="this.id = 'off'"value="<?php echo("$date"); ?>"/></td>
				</tr>
				<tr>
					<td>Received Date:</td>

					<td><input type="text"name="date_received"onFocus="this.id = 'on'"onBlur="this.id = 'off'"value="<?php echo($date); ?>"/></td>
				</tr>
			</table>
			</fieldset>
		</td>
	</tr>
</table>

</td>
</tr>

<tr>
<td align="center"><hr />

<!-- CASE INFORMATION -->
<table border="0"width="370"class="noborder">
	<tr>
		<td>
			<fieldset><legend>Case Information</legend>
			<table class="noborder">
				<tr>
					<td>Case Number:</td>
					<td><input type="text"name="case_number"onFocus="this.id = 'on'"onBlur="this.id = 'off'"></td>
				</tr>
				<tr>
					<td>State Issued:</td>
					<td><input type="text"name="state_issued"onFocus="this.id = 'on'"onBlur="this.id = 'off'"></td>
				</tr>
				<tr>
					<td>County Issued:</td>
					<td><input type="text"name="county_issued"onFocus="this.id = 'on'"onBlur="this.id = 'off'"></td>
				</tr>
				<tr>
					<td>Plaintiff:</td>
					<td><textarea rows="7"cols="30"name="plaintiff"onFocus="this.id = 'on'"onBlur="this.id = 'off'"></textarea></td>
				</tr>
				<tr>
					<td>Defendant:</td>
					<td><textarea rows="7"cols="30"name="defendant"onFocus="this.id = 'on'"onBlur="this.id = 'off'"></textarea></td>
				</tr>


<tr><td>Papers Being Served:</td><td><textarea rows="7"cols="30"name="document_type"onFocus="this.id = 'on'"onBlur="this.id = 'off'"></textarea>
</td></tr>
</table>
</fieldset><br />
</td>
</tr></table>
</td>
<td valign="top"align="center"><hr />
<table class="noborder">
	<tr>
		<td>
			<fieldset><legend>Person To Be Served Information</legend>
			<table class="noborder">
			<tr>
				<td>Person being served:</td>
				<td><input type="text" name="person_to_be_served" onfocus="this.id = 'on'" onblur="this.id='off'"/></td>
			</tr>
			<tr>
				<td>Address 1:</td>
				<td><input type="text"name="addressone"onfocus="this.id = 'on'"onblur="this.id = 'off'"/></td>			
			</tr>
							<tr>
				<td>Address 2:</td>
				<td><input type="text" name="addresstwo" onfocus="this.id = 'on'" onblur="this.id = 'off'" /></td>			
			</tr>
							<tr>
				<td>City:</td>
				<td><input type="text" name="city" onfocus="this.id = 'on'" onblur="this.id = 'off'" /></td>			
			</tr>
							<tr>
				<td>State:</td>
				<td><input type="text" name="state" onfocus="this.id = 'on'" onblur="this.id = 'off'" size="2" maxlength="2" /></td>			
			</tr>
							<tr>
				<td>Zip:</td>
				<td><input type="text" name="zip" onfocus="this.id = 'on'" onblur="this.id = 'off'" size="5" maxlength="5" /></td>			
			</tr>
			</table></fieldset><br />
		<table class="noborder">
		<tr><td>
			<fieldset><legend>Comments</legend>
			<textarea rows="7" cols="30" name="comments" onfocus="this.id='on'; this.value=''" onblur="this.id='off'" style="overflow:visible">Comments</textarea>
			</fieldset></td></tr></table>

			<div style="text-align:center;"><input type="submit" name="hold" onClick="document.getElementById('msgbox').style.display ='block';document.getElementById('blacked').style.display ='block'" value="Place Case on Hold" /> or <input type="submit" name="full" value="Continue" /></div>


</td>
</tr></table></table></div>
</form>


<?php
$client = $_POST['client'];
$attorney = $_POST['attorney'];
$server = $_POST['server'];
$case_number = $_POST['case_number'];
$state = $_POST['state_issued'];
$county = $_POST['county_issued'];
$plaintiff = $_POST['plaintiff'];
$defendant = $_POST['defendant'];
$county_issued = $_POST['county_issued'];
$state_issued = $_POST['state_issued'];
$document_type = $_POST['document_type'];
$client_reference = $_POST['client_reference'];
$date_created = $_POST['date_created'];
$date_received = $_POST['date_received'];
$person_to_be_served = $_POST['person_being_served'];
$addressone = $_POST['addressone'];
$addresstwo = $_POST['addresstwo'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$comments = $_POST['comments'];
$hold = $_POST['hold'];
$full = $_POST['full'];

// Converts teh Date Received into a MYSQL format
$date_received = ereg_replace("-", "/", "$date_received");
$date_received = explode("/", "$date_received");
$date_received = $date_received[2] . "/" . $date_received[0] . "/" . $date_received[1];

if (isset($hold))
{

// Gets the Client ID Refreenced by the Drop Down Box "Client"
$query_client = "SELECT clientID FROM client_information WHERE firmname = '$client'";
$result_client = mysql_query($query_client) or die(mysql_error());
$row_client = mysql_fetch_array($result_client);

// Gets the Attorney ID Refreenced by the Drop Down Box "Attorney"
$query_attorney = "SELECT attorneyID FROM attorney_information WHERE fullname = '$attorney'";
$result_attorney = mysql_query($query_attorney) or die(mysql_error());
$row_attorney = mysql_fetch_array($result_attorney);

// Gets the Server ID Refreenced by the Drop Down Box "Server"
$query_server = "SELECT serverID FROM server_information WHERE fullname = '$server'";
$result_server = mysql_query($query_server) or die(mysql_error());
$row_server = mysql_fetch_array($result_server);

$date = date('Y-m-d');
$status = "Being Attempted";

//INSERT THE INFORMATION
$query = "INSERT INTO case_information (date_created, date_received, case_number, plaintiff, defendant, county_issued, state_issued, document_type, person_to_be_served, addressone, addresstwo, city, state, zip, client_reference, status, clientID, attorneyID, serverID) VALUES ('$date', '$date_received', '$case_number', '$plaintiff', '$defendant', '$county_issued', '$state_issued', '$document_type', '$person_to_be_served', '$addressone', '$addresstwo', '$city', '$state', '$zip', '$client_reference', '$status', '$row_client[clientID]', '$row_attorney[attorneyID]', '$row_server[serverID]')";
mysql_query($query) or die(mysql_error());

$query = "SELECT * FROM case_information WHERE case_number = '$case_number' AND person_to_be_served = '$person_to_be_served'";
$result = mysql_query($query);
$lastID = mysql_insert_id();
$row = mysql_fetch_assoc($result);
$uniqueID = $row['uniqueID'];

$year = date('Y');
$unique_year = substr("$uniqueID", 0, 4);
$unique_specific = substr("$uniqueID", -5);

echo "The current year is $year <br>";
echo "The Last Internal ID entered is $lastID <br>";
echo "The Unique year is $unique_year <br>";
echo "The Unique Specific is $unique_specific <br>";
echo "The Unique ID is $uniqueID<br><br>";

//If this is the first record
if ($lastID == "1") {
$unique_specific = "00001";
$unique_year = $year;
echo 'Ran $lastID == "1"<br>';
}
elseif ($lastID > 1) {
$unique_specific = $unique_specific +1;
echo 'Ran $unique_year == $year<br>';
}
elseif ($unique_year > $year) {
$unique_specific = "00001";
$unique_year = $year;
echo 'Ran $unique_specific > $year<br>';
}
//elseif ($unique_year < $year) {
//die("The server's clock needs to be corrected before anything else can be done.\nThis case was not added.\nPlease contact your system administrator.");
//}

$uniqueID = $unique_year . $unique_specific;

echo "The current year is $year <br>";
echo "The Unique year is $unique_year <br>";
echo "The Unique Specific is $unique_specific <br>";
echo "The Unique ID is $uniqueID<br>";

$query = "UPDATE case_information SET uniqueID='$uniqueID' WHERE internalID = '$lastID'";
mysql_query($query) or die(mysql_error());


/*
$query_unique_id = "UPDATE case_information SET uniqueID='$last' WHERE internalID = '$lastID'";
mysql_query($query_unique_id) or die(mysql_error());
*/
echo  "
	<div id=\"msgbox\">Case Successfully added!<br />
	The Unique ID is $uniqueID<br />
	The Case ID is $case_number<br />
	<input type=submit name=closebox value=\"Close This Box\" onclick=\"getElementById('msgbox').style.display='none';getElementById('blacked').style.display='none'\" /></div>
	";

}
elseif(isset($full)) {

$person_to_be_served = $_POST['person_to_be_served'];
$addressone = $_POST['addressone'];
$addresstwo = $_POST['addresstwo'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$month = array ("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec");


echo " 
<script language=javascript>
document.newcase.style.display = 'none';
document.full.person_served.focus();
</script>
<div id=\"serve_case\">
<form name=full>
<table style=\"border:0px;\">
<tr>
	<td>
		<fieldset><legend>Service Information</legend>
		<table>
			<tr>
				<td>
					Person Served:
				</td>
				<td><input type=\"text\" onFocus=\"this.id='on'\" onBlur=\"this.id='off'\" name=\"person_served\" value=\"$person_to_be_served\" onClick=\"this.value=''\" />
			</tr>
			<tr>
				<td>
					Address One:
				</td>
				<td><input type=\"text\" onFocus=\"this.id='on'\" onBlur=\"this.id='off'\" name=\"addressone\" value=\"$addressone\" onClick=\"this.value=''\" />
			</tr>
			<tr>
				<td>
					Address Two:
				</td>
				<td><input type=\"text\" onFocus=\"this.id='on'\" onBlur=\"this.id='off'\" name=\"addresstwo\" value=\"$addresstwo\" onClick=\"this.value=''\" />
			</tr>
			<tr>
				<td>
					City:
				</td>
				<td><input type=\"text\" onFocus=\"this.id='on'\" onBlur=\"this.id='off'\" name=\"city\" value=\"$city\" onClick=\"this.value=''\"/>
			</tr>
			<tr>
				<td>
					State:
				</td>
				<td><input type=\"text\" onFocus=\"this.id='on'\" onBlur=\"this.id='off'\" name=\"state\" value=\"$state\" onClick=\"this.value=''\" />
			</tr>
			<tr>
				<td>
					Zip:
				</td>
				<td><input type=\"text\" onFocus=\"this.id='on'\" onBlur=\"this.id='off'\" name=\"zip\" value=\"$zip\" onClick=\"this.value=''\" />
			</tr>
		</table>
		</fieldset>
	</td>
	<td>
		<fieldset><legend>Date / Time</legend>
		<table>
			<tr>
				<td>
					<u>T</u>ime Served:
				</td>
				<td><input type=\"text\" onFocus=\"this.id='on'\" onBlur=\"this.id='off'\" name=\"date_served_1\" accesskey=\"t\" size=2 maxlength=2 value=\"\" />:<input type=\"text\" size=2 maxlength=2 onFocus=\"this.id='on'\" onBlur=\"this.id='off'\" name=\"date_served_2\" value=\"\" />AM<input type=radio name=\"ampm\" value=\"AM\" checked />PM<input type=radio name=\"ampm\" value=\"PM\" />
				</td>
			</tr>
			<tr>
				<td>
					Date Served:
				</td>
				<td>
					<select name=month value=$real_month>
						";
						$real_month = date('M');

						echo "<option selected>$real_month";
						foreach($month as $monthname) {
						echo "<option>$monthname</option>";
						}
					echo "

					</select>

					<select name=day value=$real_day>";
					$real_day = date('j');
					$yesterday = $real_day - 1;
					echo "<option selected>$yesterday";
					$day = array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");
					foreach($day as $daynumber) {
						echo"<option>$daynumber</option>";}
					echo "</selected>

					<select name=year value=$real_year>";
					$real_year = date('Y');
					$last_year = $real_year - 1;
					echo "<option selected>$real_year\n</option>";
					echo "<option>$last_year</option>";
					echo"</select>

			</tr>															
		</fieldset>
		</table>
</tr>
</table>
</div>";
}
?>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.