scottybwoy Posted September 26, 2006 Share Posted September 26, 2006 Hi Again,I have this small function to get a user ID from a database :[code]<?php function userLevel($user) { $this->appCon(); $user_id = mssql_result("SELECT userId FROM users WHERE uNAME = $user"); $user_level = mssql_result("SELECT level FROM users WHERE userId = " . $user_id); return $user_level; }?>[/code]And I get this error :PHP Warning: Wrong parameter count for mssql_result() in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 51 PHP Warning: Wrong parameter count for mssql_result() in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 52Line 51/2 are the queries, but basically both $vars don't exist in the database it's for a test so should these errors occur? Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/ Share on other sites More sharing options...
scottybwoy Posted September 26, 2006 Author Share Posted September 26, 2006 PHP Manual does not give any info if there is a null entry given to it or what it does if it is to return a null entry, can anyone specify so I know how to sort this function out, should be basics. I've tried putting in a link but I don't think thats where the problem lies.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99020 Share on other sites More sharing options...
wildteen88 Posted September 26, 2006 Share Posted September 26, 2006 You want to run mssql_query not mssql_result! You cannot pass an SQL query to mssql_result. mssql_results grabs the results returned from the query you passed through mssql_query. Also no need to do two sql queries to get the level. Just use one:[code]<?php function userLevel($user) { $this->appCon(); $sql = mssql_query("SELECT level FROM users WHERE uNAME = $user"); $user_level = mssql_fetch_assoc($sql); return $user_level['level']; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99028 Share on other sites More sharing options...
trq Posted September 26, 2006 Share Posted September 26, 2006 mssql_result expects a result resource, row number, and field, NOT an sql query. Try...[code=php:0]function userLevel($user) { $result = mssql_query("SELECT level FROM users WHERE uNAME = '$user'"); $level = mssql_result($ressult,0,0); return $level;}[/code]EDIT: Too slow!!! Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99029 Share on other sites More sharing options...
scottybwoy Posted September 26, 2006 Author Share Posted September 26, 2006 lol thanks,I thaught mssql_result returned the value of the one cell I was after, cheers for pointing out the 2 query issue, stupid me. ;)But I tried both your suggestion and I get an error by the = :PHP Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near '='. (severity 15) in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 43 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 43 PHP Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 44I tried it both ways round like in my first post, no joy. Any Suggestions Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99046 Share on other sites More sharing options...
wildteen88 Posted September 26, 2006 Share Posted September 26, 2006 Its your SQL query thats the error. Check that you are using the correct mssql syntax for the following query:SELECT level FROM users WHERE uNAME = $userPrehaps it should be:SELECT `level` FROM `users` WHERE `uNAME`='$user' Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99053 Share on other sites More sharing options...
scottybwoy Posted September 26, 2006 Author Share Posted September 26, 2006 OK This is "sort of" working for me now :[code]<?php function userLevel($user) { $this->appCon(); $sql = mssql_query("SELECT level FROM users WHERE uNAME = '" . $user . "'"); $user_level = mssql_result($sql,0); return $user_level; }?>[/code]Now back to my first question, how does mssql_result work?I now get this error:PHP Warning: Wrong parameter count for mssql_result() in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 51Thanks for ya patienceBy the way Wildteen, when I used ur suggestion I got syntax errors all over the place. Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99062 Share on other sites More sharing options...
scottybwoy Posted September 27, 2006 Author Share Posted September 27, 2006 *** PROBE *** I understand the perameters, i.e 'level' = the column, 'users' = the table, '$user' = the uNAME column. So it seems to me the right parameter count. This is my fuction that calls userLevel :[code]<?php function __construct() { echo $this->getName(); echo "<BR/>"; echo $this->authorise($this->getName); echo "<BR/>"; echo $this->userLevel($this->getName); }?>[/code]And the name passed in does not exist in the database at all. So is it meant to give that error? Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99463 Share on other sites More sharing options...
shoz Posted September 27, 2006 Share Posted September 27, 2006 [quote author=scottybwoy link=topic=109539.msg441822#msg441822 date=1159288186][code]$user_level = mssql_result($sql,0);[/code]Now back to my first question, how does mssql_result work?I now get this error:PHP Warning: Wrong parameter count for mssql_result() in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 51[/quote][url=http://php.net/mssql_result]mssql_result()[/url] takes 3 arguments. Unlike mysql_result, the "field" parameter does not appear to be optional.[code]mssql_result($sql, 0, 0);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99485 Share on other sites More sharing options...
scottybwoy Posted September 27, 2006 Author Share Posted September 27, 2006 Hi Shoz,Yeah I tried that before and I get a diffrent error about a row offset :PHP Warning: mssql_result() [function.mssql-result]: Bad row offset (0) in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 51However, I have used this function before and never put 'field' perameters in and it has worked. As it is only returning a single cell key I don't see why it needs these perameters, well from what I can see ,0,0 represent row1, column1, which is just the cell returned. Please note again that basically it should find no value at all, should it be returning these kinds of messages?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99488 Share on other sites More sharing options...
shoz Posted September 27, 2006 Share Posted September 27, 2006 [quote author=scottybwoy link=topic=109539.msg442272#msg442272 date=1159349685]Hi Shoz,Yeah I tried that before and I get a diffrent error about a row offset :PHP Warning: mssql_result() [function.mssql-result]: Bad row offset (0) in C:\Inetpub\wwwroot\database\classes\mri_central1.php on line 51However, I have used this function before and never put 'field' perameters in and it has worked. As it is only returning a single cell key I don't see why it needs these perameters, well from what I can see ,0,0 represent row1, column1, which is just the cell returned. Please note again that basically it should find no value at all, should it be returning these kinds of messages?Thanks[/quote]You should be able to use mssql_num_rows to determine if any rows have been sent. The error you quote above is most likely related to the fact that no rows were returned as you suspected. [code]if (mssql_num_rows($sql)){ $level = mssql_result($sql, 0, 0);}The "Parameter" error however will most likely persist if you don't specify the 3rd argument. I don't have any experience with "mssql", but the manual does not show the 3rd argument as being optional which is usually denoted by brackets("[..]") surrounding the parameter in the function prototype.http://www.php.net/manual/en/about.prototypes.php[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99538 Share on other sites More sharing options...
scottybwoy Posted September 27, 2006 Author Share Posted September 27, 2006 Re-wrote the function, got it working[code]<?php function userLevel($user) { $this->appCon(); $sql = mssql_query("SELECT level FROM users WHERE uNAME = '" . $user . "'"); if (!row == mssql_fetch_row($sql)) { die ("You do not have any access"); } else { $user_level = mssql_result($sql, 0, 0); } return $user_level; }?>[/code]Thanks to all who helped Quote Link to comment https://forums.phpfreaks.com/topic/22097-parameter-count-and-query-issues-solved/#findComment-99539 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.