Jump to content

Recommended Posts

<?php
session_start();
$username = 'matthew798';
include 'dbconnect.php';

$q = mysql_query("SELECT permission FROM users WHERE username = '$username'")
or die(mysql_error()); 

$permissions = explode(",", $q);

print_r($permissions);

if ( $permissions['0'] == 0 ){
die('You do not have permission to access this administrative function');
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<LINK REL=StyleSheet HREF="stylemain.css" TYPE="text/css" MEDIA=screen />
</head>

<body bgcolor="black">

<table border="0">
  <tr>
    <td><form action="newsprocess.php" method="POST">
      <span class='headline'>Title</span><br />
      <input name="title" type="text" class='textinputhead' />
<br /><br />
<span class='headline'>Body</span><br />
<textarea name="body" type="text" class='textinputbody' /></textarea><br /><br />
      <input type="submit" value='Post News' class='textinputsubmit'/>
    </form></td>

  </tr>
</table>

</body>
</html>

 

I keep getting this.

Array ( [0] => Resource id #4 )

 

 

1: Now a few things i want you to look at, the IF statement. If the value IS NOT 0, then it should just continue with the rest of the page, right?

2: Why isnt it returning all the permission values in the array? (the value in the DB is "1,1,1", i checked)

3: All i have to do is session_start() and it loads all $_SESSION variables i had when they logged in right?

 

 

I just re-posted this here because the other topic was getting too crowded for my already withered PHP mind... I couldn't find anything anymore. Anyways now it has an appropriate title!

Try fetching the results:

$q = mysql_query("SELECT permission FROM users WHERE username = '$username'")
or die(mysql_error());

$row = mysql_fetch_assoc($q);
$permissions = explode(", ", $row[permission]);

print_r($permissions);

if ( $permissions['0'] == 0 ){
die('You do not have permission to access this administrative function');
}

Thanks!!! IT WORKS!!!! Only thing is:

 

Notice: Use of undefined constant permission - assumed 'permission' in C:\Program Files\EasyPHP 2.0b1\www\admin\adminnews.php on line 10

 

Comes from a typo I had in the code.  Try:

$permissions = explode(", ", $row['permission']);

hehe no more warning!

 

But is it normal that Array ( [0] => 1,1,1 )

 

shouldnt

[0] => 1

--

[1] => 1

--

[2] => 1

?

 

Theres three permissions... Different pages call diferent vars within the string (dunno if my PHP grammar is good there lol)

 

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.