Jump to content

Parameter Count and Query issues **SOLVED**


scottybwoy

Recommended Posts

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 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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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!!!
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 51

Thanks for ya patience

By the way Wildteen, when I used ur suggestion I got syntax errors all over the place.
Link to comment
Share on other sites

*** 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?
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[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 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
[/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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.