Jump to content


Photo

Parameter Count and Query issues **SOLVED**


  • Please log in to reply
11 replies to this topic

#1 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 26 September 2006 - 01:48 PM

Hi Again,

I have this small function to get a user ID from a database :

<?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;
	}
?>

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 52

Line 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?

#2 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 26 September 2006 - 03:42 PM

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

#3 wildteen88

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

Posted 26 September 2006 - 03:51 PM

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:
<?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'];
	}

?>


#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 September 2006 - 03:52 PM

mssql_result expects a result resource, row number, and field, NOT an sql query. Try...

function userLevel($user) {
  $result = mssql_query("SELECT level FROM users WHERE uNAME = '$user'");
  $level = mssql_result($ressult,0,0);
  return $level;
}

EDIT: Too slow!!!

#5 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 26 September 2006 - 04:11 PM

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 44

I tried it both ways round like in my first post, no joy.  Any Suggestions

#6 wildteen88

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

Posted 26 September 2006 - 04:20 PM

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 = $user

Prehaps it should be:
SELECT `level` FROM `users` WHERE `uNAME`='$user'

#7 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 26 September 2006 - 04:29 PM

OK This is "sort of" working for me now :
<?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;
	}
?>
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

Thanks for ya patience

By the way Wildteen, when I used ur suggestion I got syntax errors all over the place.

#8 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 27 September 2006 - 08:17 AM

*** 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 :
<?php
	function __construct()
	{
		echo $this->getName();
		echo "<BR/>";
		echo $this->authorise($this->getName);
		echo "<BR/>";
		echo $this->userLevel($this->getName);
	}
?>
And the name passed in does not exist in the database at all.  So is it meant to give that error?

#9 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 27 September 2006 - 09:21 AM

$user_level = mssql_result($sql,0);
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

mssql_result() takes 3 arguments. Unlike mysql_result, the "field" parameter does not appear to be optional.

mssql_result($sql, 0, 0);


#10 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 27 September 2006 - 09:34 AM

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 51

However, 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

#11 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 27 September 2006 - 11:49 AM

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 51

However, 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


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.

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


#12 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 27 September 2006 - 11:50 AM

Re-wrote the function, got it working
<?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;
	}
?>

Thanks to all who helped




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users