3

I am working on a piece that allows user to create an article, but there are some restricted for an admin, which i identify as SgroupId 1. Now when I log in with my admin code, i realize i still cant post everything, except for what I identified in loadTypeUsers. I know i get the value of Sgroup1 with me, since the admin panel loads in the bar below. Also when I echo the value I get the return of 1, which should be fine.

But when I try to load the dropdown in my popup, it wont give me the full list. Instead, it loads just the list I specified in the LoadTypeUsers. Can somebody help me out here?

Thanks in advance.

~Dorv

function MakeArticleTypeDropdown(){
        echo "<select name='ArticleTypeId'>";

        if($SgroupId == 1 || $SgroupId == 1){ 
            $results = LoadType();
        }
        else
        {
            $results = LoadTypeUsers();
        }

        while($row = mysql_fetch_array($results)){
            echo "<option value='".$row['ArticleTypeId']."'>"
                            .$row['ArticleTypeName']."</option>";
        }
        echo "</select>";
    }

This is tucked in the ArticleFunction.php file

function LoadTypeUsers(){
    $query = "SELECT * FROM Articletype limit 1,3;";
    $resultaat=SendQuery($query);
    return $resultaat;
}

    function LoadType(){
    $query = "SELECT * FROM Articletype;";
    $resultaat=SendQuery($query);
    return $resultaat;
}

This is tucked in the Sentry.php file

session_start();
$UserName = $_SESSION['username'];

$result = mysql_query("select * from user where username='".$UserName."'");
while($row = mysql_fetch_array($result)){
                $UserId = $row['UserId'];
                $CharacterName = $row['CharacterName'];
                $UserName = $row['UserName'];
                $SgroupId = $row['SgroupId'];
            };
4
  • Where does the $SgroupId varialbe should come from in the MakeArticleTypeDropdown function? From here it seem to be undefined. Commented Aug 17, 2012 at 12:27
  • either pass it to the function MakeArticleTypeDropdown($SgroupId) or use global $SgroupId; inside the function so it has access to the outside value; Commented Aug 17, 2012 at 12:29
  • 1
    rabble rabble mysql_* rabble rabble open to sql injection rabble rabble strict type-checking rabble rabble row is open to xss rabble Commented Aug 17, 2012 at 12:29
  • just curiousity : why this if($SgroupId == 1 || $SgroupId == 1)? (repeated) or its a typo!!! Commented Aug 17, 2012 at 12:30

3 Answers 3

3

$SgroupId is not defined in the function MakeArticleTypeDropdown() so it will always goes in else condition .Try something as follows

MakeArticleTypeDropdown($SgroupId)
{
//-----------your code
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, that fixed the problem. I feel really dumb I overlooked to shoot the groupId to the function! thank you very much
it happens often with us that is why such community and forums are there to help each other.thanks for your comment :)
3

first of all, I don't see you passing the value of $SgroupId to MakeArticleTypeDropdown(). Maybe you have an scope problem and you're checking a variable $SgroupId that isn't set inside the function?

second: ($SgroupId == 1 || $SgroupId == 1) What is that || for?

1 Comment

it's a typo, sorry, it should have been ($SgroupId == 1 || $SgroupId == 2)
1

I think that the LIMIT clause should be a WHERE clause.

i.e.

SELECT * FROM Articletype WHERE SgroupId = 1 OR SgroupId = 3

and perhaps the line

if($SgroupId == 1 || $SgroupId == 1){  

should read

if($SgroupId == 1 || $SgroupId == 3){  

4 Comments

I tried it with a where clause, but it made the query a tat long, and its just i need statements 2,3 and 4 out of the table. I thought this was the right solution and it works for me. The table itself has no SgroupId linked to it. The articleType table just defines the numbers within the article table.
The LIMIT just limits the number of rows retrieved. What was implied is not that. Perhaps an edit of the question (please do not edit the existing text but add further imformation).
i gotcha, i will look into this, but I can tell you that the ArticleType table just has 2 fiels, which is ArticleTypeId (which runs to the Article table) and the definition of each Id, 1 being announcement, 2 being article and so on. So I dont understand in this case where the SgroupId from you comes in. You want me to add another fieldset in my database where I state that that one is usable being each group? Sorry, cause you lost me there, Ed.
Just a hunch that the PHP variable name is the same as the column name and hence the two functions, one with LIMIT would use that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.