Jump to content


Photo

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


  • Please log in to reply
9 replies to this topic

#1 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 01 September 2006 - 03:02 PM

My query:

$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);

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?



#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 September 2006 - 03:04 PM

.. or die("Either the Employee Number or SSN you entered was invalid");

Like that, or 'friendlier'?
Legend has it that reading the manual never killed anyone.
My site

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 01 September 2006 - 03:12 PM

Concatenate it with "Would you like a hug?" for extra friendliness.

#4 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 01 September 2006 - 03:29 PM

.. or die("Either the Employee Number or SSN you entered was invalid");

Like that, or 'friendlier'?


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



#5 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 01 September 2006 - 03:35 PM

Concatenate it with "Would you like a hug?" for extra friendliness.


No, something more like this:

Posted Image

;D

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 September 2006 - 03:53 PM

.. or die("Either the Employee Number or SSN you entered was invalid");

Like that, or 'friendlier'?


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


If they enter an invalid entry for either, it throws a SQL error.


So the combined effect was along the lines of:

$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!");

Legend has it that reading the manual never killed anyone.
My site

#7 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 01 September 2006 - 04:01 PM

also for a slightly more helpful contribution:

<?php

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

?>


#8 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 01 September 2006 - 04:28 PM

.. or die("Either the Employee Number or SSN you entered was invalid");

Like that, or 'friendlier'?


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


If they enter an invalid entry for either, it throws a SQL error.


So the combined effect was along the lines of:

$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!");


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!

:)

#9 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 01 September 2006 - 04:30 PM

By the way, I don't suppose there's a way to use HTML formatting within a die statement, is there?



#10 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 September 2006 - 04:33 PM

Yes just type it as normal. But if use double quotes in your html make sure you add a slash infront of them, eg:
$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>");





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users