Jump to content

[SOLVED] Hello everyone


3raser

Recommended Posts

Hello everyone,

 

First timer using the phpfreaks support section, and even posting on this forum. I see this forum is very active, so I decided to join. Codingforums is very un-active. Anyways, I have the following code:

 

<?php require "global_navigation.php"; ?>
<?php

$name = $_SESSION['username'];

//connect to database
$connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!");
mysql_select_db("$db") or die("Database fail!");


//extract
$extract = mysql_query("SELECT * FROM users WHERE username='$name'");
$numrows = mysql_num_rows($extract);

while ($row = mysql_fetch_assoc($extract))

{
           $staffcheck = $row[staff]; 
}

if ($staffcheck ==1&&2) 
{

echo "<div class='box'>
<h3>Delete a post</h3>
<form action='deletepost.php' method='POST'>
Message ID: <input type='text' name='id'><input type='submit' value='Delete'><hr>
</form>
<h3>Edit a post</h3>
<form action='edit.php' method='POST'>
Message ID: <input type='text' name='id'><br><br>
New message<br>
<textarea rows='10' cols='30' name='message'>
</textarea><br>
<input type='submit' value='Edit'><hr>
</form>
<h3>Ban IP (Coming soon)</h3>
<input type='text' name='code'>
<input type='submit' value='Ban'><hr>
</form>
</div> ";

}
else
{
echo "<center><b><span style='color:red'>Only admin and moderators can enter this area!</span></b>"; 
}

?>
</font></td>
										</tr>
									</tbody>
								</table></td>
							</tr>
						</tbody>
					</table>
					</td>
				</tr>
			</tbody>
		</table>
		</center>
		<table class="tborder" cellpadding="4" cellspacing="1" width="67%">
			<tbody>
				<tr>
					<td class="thead"><font face="Trebuchet MS"><strong>  
					Copyright</strong></font></td>
				</tr>
				<tr>
					<td class="trow1">
					<table border="0" cellpadding="4" width="100%">
						<tbody>
							<tr>
								<td class="trow1">
								<p align="center">
<span class="smalltext" style="display: inline; visibility: visible; font-family: Trebuchet MS; font-weight: 700">
<a title="Simple Machines Forum" target="_blank" class="new_win" href="http://commentbb.com">
<font size="2">Powered by CommentBB 1.0 BETA</font></a><font size="2"> |
</font><a href="http://commentbb.com"><font size="2">CBB is © 2009, CommentBB 
INC</font></a></span></td>
							</tr>
						</tbody>
					</table></td>
				</tr>
			</tbody>
		</table> </div>
<font face="Trebuchet MS">
<!-- end: footer -->
<!-- end: portal --></font></body></html>

 

I'm focusing more on this line out of any other:

 

if ($staffcheck ==1&&2) 
{

 

I have an admin account on my script, correct? So, I'm trying to make it so Moderators can access the ModCP, of course, if they have the required staff level. It's 1 for moderators. And I also want to give admins access, since, well, they are admins. So I used the and signs, but I'm not sure if thats correct. I'm thinking it should be an OR, or something. And it's not allowing me in, and my user level in the database is 2.

 

If you have any questions on what I'm trying to get at, please ask!

Link to comment
https://forums.phpfreaks.com/topic/179676-solved-hello-everyone/
Share on other sites

Firstly $staffcheck can't be equal to 2 different values so AND is obviously not what your after, you want OR which is ||. Also you can't compare 1 variable to 2 values in that manner. Sounds like your after...

 

if($staffcheck == 1 || $staffcheck == 2) {

 

... you could possibly use >= 1 or vice versa depending on what order you user rights go in.

 

Edit: d'oh.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.