scottybwoy Posted August 18, 2008 Share Posted August 18, 2008 I have a number of sql abstraction functions, but this one always displays a notice message, but returns the correct result. What do I need to iron out? function selectRecord($record, $tbl, $col, $val) { $sql = "SELECT $record FROM $tbl WHERE $col = "; if (is_int($val)) { $sql .= "$val"; } else { $sql .= "'" . $val . "'"; } //echo $sql; $qry = mssql_query($sql); $res = mssql_result($qry, 0, 0) or trigger_error("$sql Failed", E_USER_NOTICE); return $res; } Thanks. Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted August 19, 2008 Author Share Posted August 19, 2008 It's really annoying as I want to print the results of a page, but without having the notices flag up. Why does it keep displaying them, even though it returns the data correctly? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted August 19, 2008 Share Posted August 19, 2008 $sql = "SELECT $record FROM $tbl WHERE $col = "; Add backticks $sql = "SELECT `$record` FROM `$tbl` WHERE `$col` = "; Just incase they enter a reserved table/fieldname ??? Quote Link to comment Share on other sites More sharing options...
samshel Posted August 19, 2008 Share Posted August 19, 2008 what are the notices displayed? Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted August 19, 2008 Author Share Posted August 19, 2008 Sorry, I should have mentioned I'm using MsSQL, which doesn't like backticks. The notice that is being displayed is : PHP Warning: mssql_result() [function.mssql-result]: Bad row offset (0) in D:\Inetpub\wwwroot\testing\classes\mri_central.php on line 348 When I comment out the E_USER_NOTICE And it displays my error when its not, which displays something like : PHP Notice: SELECT name FROM client WHERE clientId = 'NOR0000' Failed in D:\Inetpub\wwwroot\testing\classes\mri_central.php on line 348 If I copy and paste that into a query window, it returns the expected result, as it does normally. Quote Link to comment 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.