Jump to content

Change User rank


dean7

Recommended Posts

Hi all, the other I coded a simular script to this which didnt work, so I re coded it but im having a problem with this one aswell, what its meant to do is just change the users rank to what is posted, but every time I hit submit on the form it locates me to a different place.

 

<?php
session_start();

include ("../includes/db_connect.php");
include ("../includes/functions.php");
logincheck();


$username = $_SESSION['username'];

$rankget = mysql_query ("SELECT * FROM users WHERE username='$username'");
	$newrank = mysql_fetch_object($rankget);

if ($_POST['change']){
if ($newrank->userlevel >= "2"){

$time = now();	
$updateuser = $_POST['usernameone'];	  // User Posted
$updaterank = $_POST['rankone'];		 // Rank posted

if ($updateuser == NULL && $updaterank == NULL){
$message = "You must enter a user and rank";
}elseif ($updateuser == NULL){
$message = "You must enter a username";
}elseif ($updaterank == NULL){
$message = "You must enter a rank";
}

mysql_query ("UPDATE users SET rank = '$updaterank' WHERE username='$updateuser'") or die (mysql_error());
mysql_query ("INSERT INTO logs (`id` , `who`, `action`, `time`) VALUES ('', '$username' , '$username Updated rank; $updateuser to $updaterank' , '$time')") or die (mysql_error());
mysql_query ("INSERT INTO inbox (`id` , `to` , `from` , `message` , `date` , `read` , `saved` , `event_id`) VALUES ('', '$updateuser', 'System', 'Your rank has been updated to $updaterank!', '$date', '0', '0', '')") or die (mysql_error());
echo ("Rank Changed!");
}}
?>
<html>
<head>
<title>Change Rank</title>
<link rel="stylesheet" href="../include/in.css" type="text/css">
<style type="text/css">
.infobg {
font-family: Arial;
font-weight:normal;
font-size:12px;
border-top: 1px solid #000000;
border-right: 1px solid #000000;
border-bottom: 1px solid #000000;
border-left: 1px solid #000000;
background: URL(textbg1.png);
font-weight:300;
}

.button {
font-size: 12px;
background:url(button.png);
vertical-align: middle;
border-top: 1px solid #000000;
border-right: 1px solid #000000;
border-bottom: 1px solid #000000;
border-left: 1px solid #000000;
color: #FFFFCC;
height:23px;
font-weight:300;
border-radius: 10px;
padding-bottom:2px;
}

</style>
</head>
<body>
<form action='' name='form1' id='form1' method='POST'>
<table width='50%' cellpadding='0' align='center' cellspacing='0' border='1' bordercolor='#000000' bgcolor='#808080' style='border-collapse: collapse'>
  <tr>
  <td><?php echo ("$message"); ?></td>
  </tr>	
  <tr>
  <td background='../header.jpg' colspan='2' align='center'>Change Rank</td>
  <tr>
  <td>Username:</td><td><input type='text' name='usernameone'></td>
  </tr>
  <tr>
  <td>Rank:</td><td><input type='text' name='rankone'></td>
  </tr>
  <tr>
  <td> </td><td><input type='submit' name='change' value='Change Rank!'></td>
  </tr>
</table>
</form>
</body>
</html>

 

Anyone see why it locates me else?

 

Thanks

Link to comment
Share on other sites

It's because the action='' attribute of your form tag:

<form action='' name='form1' id='form1' method='POST'>

 

Is empty. That needs to be a URL referring to the script itself in order for this method to work. For portability when you change file names, you can use:

 

action="<?php echo $_SERVER['PHP_SELF']; ?>"

 

And the name of that file will automatically be filled in there.

Link to comment
Share on other sites

It's because the action='' attribute of your form tag:

<form action='' name='form1' id='form1' method='POST'>

 

Is empty. That needs to be a URL referring to the script itself in order for this method to work. For portability when you change file names, you can use:

 

action="<?php echo $_SERVER['PHP_SELF']; ?>"

 

And the name of that file will automatically be filled in there.

Ive changed it to that, but its still doing the same. :(

Link to comment
Share on other sites

Actually in all major browsers if the action attribute is empty or not passed it'll default to the same page.

 

@dean7

Since your update query code contains no form of redirect, the error must be somewhere else. What does logincheck() look like?

Link to comment
Share on other sites

Actually in all major browsers if the action attribute is empty or not passed it'll default to the same page.

 

@dean7

Since your update query code contains no form of redirect, the error must be somewhere else. What does logincheck() look like?

function logincheck(){


if (empty($_SESSION['username'])){
echo "
<SCRIPT LANGUAGE='JavaScript'>
window.location='index.php';

</script>
";
exit();
}}

 

That is in my functions file.

Link to comment
Share on other sites

Actually in all major browsers if the action attribute is empty or not passed it'll default to the same page.

 

@dean7

Since your update query code contains no form of redirect, the error must be somewhere else. What does logincheck() look like?

function logincheck(){


if (empty($_SESSION['username'])){
echo "
<SCRIPT LANGUAGE='JavaScript'>
window.location='index.php';

</script>
";
exit();
}}

 

That is in my functions file.

 

Are you being redirected to index.php?

Link to comment
Share on other sites

It's because the action='' attribute of your form tag:

<form action='' name='form1' id='form1' method='POST'>

 

Is empty. That needs to be a URL referring to the script itself in order for this method to work. For portability when you change file names, you can use:

 

action="<?php echo $_SERVER['PHP_SELF']; ?>"

 

And the name of that file will automatically be filled in there.

 

Using $_SERVER['PHP_SELF'] as a form's action attribute is a bad idea, actually. It opens the script up to XSS exploits. To submit a form to itself, use action=""

Link to comment
Share on other sites

You know I'm glad someone corrected me on that, it actually hasn't come up for a while because all of my forms submit via Ajax or to hidden iframes, but it's still good to know. It was the way I was taught and I just never heard (or saw) anyone do otherwise. action='#' is the other method I've seen to accomplish the same.

Link to comment
Share on other sites

Actually in all major browsers if the action attribute is empty or not passed it'll default to the same page.

 

@dean7

Since your update query code contains no form of redirect, the error must be somewhere else. What does logincheck() look like?

function logincheck(){


if (empty($_SESSION['username'])){
echo "
<SCRIPT LANGUAGE='JavaScript'>
window.location='index.php';

</script>
";
exit();
}}

 

That is in my functions file.

 

Are you being redirected to index.php?

Nope, im only getting redirected when im not logged in.

Link to comment
Share on other sites

Whenever I'm debugging some truly mysterious behavior the first thing I do is simplify everything I possibly can. Though it's not likely to solve your problem, I would start by changing that JavaScript to a

 

header('Location: http://www.example.com/index.php');

 

call, which is a more standard (and faster) way of accomplishing what your JavaScript is doing under those circumstances.

 

Can you share the contents of /includes/functions.php?

Link to comment
Share on other sites

Whenever I'm debugging some truly mysterious behavior the first thing I do is simplify everything I possibly can. Though it's not likely to solve your problem, I would start by changing that JavaScript to a

 

header('Location: http://www.example.com/index.php');

 

call, which is a more standard (and faster) way of accomplishing what your JavaScript is doing under those circumstances.

 

Can you share the contents of /includes/functions.php?

No I carnt to be honest, as the file is rather big. But also the change rank script dont really have nothing todo with the functions file.. All in the functions file is the things like owners of props , or if there logged in or not etc..

Link to comment
Share on other sites

If you're simply being taken to a blank page, it is possible that PHP is encountering a fatal error and you have error reporting turned off so cannot see what it is. Trying adding this to the top of your PHP code and try it again:

 

 error_reporting(E_ALL);
ini_set('display_errors', 1);

 

For instance there could be a problem with your mysql_fetch_object() call but you would only get a blank page if that were the case if your error reporting is off.

Link to comment
Share on other sites

If you're simply being taken to a blank page, it is possible that PHP is encountering a fatal error and you have error reporting turned off so cannot see what it is. Trying adding this to the top of your PHP code and try it again:

 

 error_reporting(E_ALL);
ini_set('display_errors', 1);

 

For instance there could be a problem with your mysql_fetch_object() call but you would only get a blank page if that were the case if your error reporting is off.

I did have that on there and it didnt show me any errors.. :S

Link to comment
Share on other sites

Try commenting out your call to session_start(), logincheck(), and $username = $_SESSION['username'];

 

In other words, first try commenting out everything that has to do with the login code. If it works without that at least you know to focus on an issue with the session/login handling and it will make fixing the problem (since it is the non-obvious type) much faster.

 

Do either of the included files have exit() calls in them anywhere?

Link to comment
Share on other sites

Try commenting out your call to session_start(), logincheck(), and $username = $_SESSION['username'];

 

In other words, first try commenting out everything that has to do with the login code. If it works without that at least you know to focus on an issue with the session/login handling and it will make fixing the problem (since it is the non-obvious type) much faster.

 

Do either of the included files have exit() calls in them anywhere?

Yeah some have them at the end of the function like the logincheck

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.