Jump to content

Archived

This topic is now archived and is closed to further replies.

Moron

I want a friendly error, not a SQL error....

Recommended Posts

My query:

[code]$RESULTDS=mssql_query("SELECT DISTINCT LH.[Employee Number], LH.[Lmo], LH.[Lda], LH.[LYR], LH.[Hours], LH.[Leave Code], M2.[HRYRAT], M2.[EMPNO], M2.[MANLAP], M2.[MANLAC], M2.[MANLTC], M2.[MSKLAB], M2.[MSKLTC], M2.[MSKLAB], M2.[MSKLTC], M2.[NAMEMI], M2.[NAMEL], M2.[NAMEF] FROM LEAVHST LH INNER JOIN MASTERL2 M2 ON LH.[Employee Number]=M2.EMPNO WHERE M2.[EMPNO] = '".$_POST['employeenumber']."' and
M2.[MSSNO] = '".$_POST['password']."' and (LH.[LYR] = '$last' AND LH.[Lmo] >= '07') OR (LH.[LYR] = '$last' + 1  AND LH.[Lmo] < '07')  ORDER BY LH.[LYR] desc, LH.[Lmo] desc, LH.[Lda] desc");
$RESULT=mssql_fetch_assoc($RESULTDS);[/code]

I have an employee leave program in the works. If they enter their employee number with matching SSN, it works great. If they enter an invalid entry for either, it throws a SQL error.

Rather than an "ugly" SQL error, I want it to tell them "Invalid Employee Number" or "Invalid SSN." They can't leave either field blank because I have Javascript validation on the form.

What's the best way to handle this?

Share this post


Link to post
Share on other sites
.. or die("Either the Employee Number or SSN you entered was invalid");

Like that, or 'friendlier'?

Share this post


Link to post
Share on other sites
Concatenate it with "Would you like a hug?" for extra friendliness.

Share this post


Link to post
Share on other sites
[quote author=AndyB link=topic=106507.msg425983#msg425983 date=1157123077]
.. or die("Either the Employee Number or SSN you entered was invalid");

Like that, or 'friendlier'?
[/quote]

Interesting, but doesn't it have to successfully connect to the database before it'll know if the entry was valid or not?

Share this post


Link to post
Share on other sites
[quote author=Jenk link=topic=106507.msg425986#msg425986 date=1157123529]
Concatenate it with "Would you like a hug?" for extra friendliness.
[/quote]

No, something more like this:

[img]http://mywebpages.comcast.net/techie4/empwrong.gif[/img]

;D

Share this post


Link to post
Share on other sites
[quote author=Moron link=topic=106507.msg425997#msg425997 date=1157124596]
[quote author=AndyB link=topic=106507.msg425983#msg425983 date=1157123077]
.. or die("Either the Employee Number or SSN you entered was invalid");

Like that, or 'friendlier'?
[/quote]

Interesting, but doesn't it have to successfully connect to the database before it'll know if the entry was valid or not?
[/quote]

[quote]If they enter an invalid entry for either, it throws a SQL error. [/quote]

So the combined effect was along the lines of:

[code]$query = "SELECT distinct .... whatever the query is ...";
$RESULTDS = mssql_query($query) or die("Hi, there ..... use the 'back' key to go back and do it properly!");[/code]

Share this post


Link to post
Share on other sites
also for a slightly more helpful contribution:

[code]<?php

$result = @mssql_query($theQuery) die('Error with Query');

?>[/code]

Share this post


Link to post
Share on other sites
[quote author=AndyB link=topic=106507.msg426011#msg426011 date=1157126023]
[quote author=Moron link=topic=106507.msg425997#msg425997 date=1157124596]
[quote author=AndyB link=topic=106507.msg425983#msg425983 date=1157123077]
.. or die("Either the Employee Number or SSN you entered was invalid");

Like that, or 'friendlier'?
[/quote]

Interesting, but doesn't it have to successfully connect to the database before it'll know if the entry was valid or not?
[/quote]

[quote]If they enter an invalid entry for either, it throws a SQL error. [/quote]

So the combined effect was along the lines of:

[code]$query = "SELECT distinct .... whatever the query is ...";
$RESULTDS = mssql_query($query) or die("Hi, there ..... use the 'back' key to go back and do it properly!");[/code]

[/quote]

BOOYAH! That works (with my own message, of course). Wow. I didn't realize that you could use an "or die" statement in a query. I've only seen it in a connect statement.

Thanks, Andy!

:)

Share this post


Link to post
Share on other sites
By the way, I don't suppose there's a way to use HTML formatting within a die statement, is there?

Share this post


Link to post
Share on other sites
Yes just type it as normal. But if use double quotes in your html make sure you add a slash infront of them, eg:
[code=php:0]$result = mssql_query('blah ...') or die("<span style=\"color: red; font-wight: bold\">There appears to be an internal error. Please come back later</span>");[/code]

Share this post


Link to post
Share on other sites

×

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.