Moron Posted September 1, 2006 Share Posted September 1, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/ Share on other sites More sharing options...
AndyB Posted September 1, 2006 Share Posted September 1, 2006 .. or die("Either the Employee Number or SSN you entered was invalid");Like that, or 'friendlier'? Quote Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84066 Share on other sites More sharing options...
Jenk Posted September 1, 2006 Share Posted September 1, 2006 Concatenate it with "Would you like a hug?" for extra friendliness. Quote Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84069 Share on other sites More sharing options...
Moron Posted September 1, 2006 Author Share Posted September 1, 2006 [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 Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84079 Share on other sites More sharing options...
Moron Posted September 1, 2006 Author Share Posted September 1, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84084 Share on other sites More sharing options...
AndyB Posted September 1, 2006 Share Posted September 1, 2006 [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 Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84093 Share on other sites More sharing options...
Jenk Posted September 1, 2006 Share Posted September 1, 2006 also for a slightly more helpful contribution:[code]<?php$result = @mssql_query($theQuery) die('Error with Query');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84098 Share on other sites More sharing options...
Moron Posted September 1, 2006 Author Share Posted September 1, 2006 [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! :) Quote Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84109 Share on other sites More sharing options...
Moron Posted September 1, 2006 Author Share Posted September 1, 2006 By the way, I don't suppose there's a way to use HTML formatting within a die statement, is there? Quote Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84110 Share on other sites More sharing options...
wildteen88 Posted September 1, 2006 Share Posted September 1, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/19375-i-want-a-friendly-error-not-a-sql-error/#findComment-84111 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.