Jump to content

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


Moron

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?

Link to comment
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?

Link to comment
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]
Link to comment
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!

:)
Link to comment
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]
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.