Die() or echo to handle if statement

Hi. I have been working on a survey all works great. Just wondering if I’m handing this the right way or not. After a code is entered and submitted I run it through a couple of checks. First is the code proper length (10 digits), is the code in the database and has this code been used. If the code passes all of these. I then start session and the survey can be completed. sample code below.


if($rowCheck >= "1") {
		 $row = mysql_fetch_array($query);
		$status = $row['status'];
		$washcode = $row['washCode'];
		}
		if($status == "1"){
		die('<div align="center"><h1>Error the code you have entered has already been used.</h1><form action="'. $_SERVER['PHP_SELF'].'" method="POST">
	<tr>
		<th colspan="2">Please check your code and try again.<br />
	 <input type="text" name="code" autocomplete="off"><br />
	<input type="submit" name="submitcode" value="Submit Code"></th>
	</tr>
</form></div>');
		
		}
		else {
		session_start();
		$_SESSION['code'] = $code;
		$_SESSION['redeemCode'] = $washcode;
		echo '<div align="center"><b>Thank you for taking the time to complete our survey. Please click the link below to begin.<br /><a href="visitdate.php"><button type="button">Next</button></a></b></div>';
		}

My main concern is that if the code does not pass this check I am currently using die(), and the rest of the page is not loaded leaving off the html footer and side nav. I am wanting to switch to echo’‘; to handle the error. Would this be alright? And can I get a little info on when it is best to use die(); instead of echo’';

I am working on converting all of my sql to mysqli when I started thinking about this.

For me, die() should be a rare sight in production code. It should be used only when the error is unrecoverable. Even then, for most cases you’ll want to have a nice message with a full page, etc.

Thanks QMonkey. That’s what I started thinking when I started going through the code tonight. Not sure why I was using die(). But I’ll be changing them to echo tomorrow. Thanks again for your reply.

how about throwing exceptions?