dean7 Posted August 31, 2010 Share Posted August 31, 2010 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 Quote Link to comment Share on other sites More sharing options...
trq Posted August 31, 2010 Share Posted August 31, 2010 Anyone see why it locates me else? Pardon? Quote Link to comment Share on other sites More sharing options...
dean7 Posted August 31, 2010 Author Share Posted August 31, 2010 Anyone see why it locates me else? Pardon? Sorry that was meant to be "Anyone else see's why it locates me else where." But now ive change change it, its just showing a white page once I click submit. Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
dean7 Posted August 31, 2010 Author Share Posted August 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
Adam Posted August 31, 2010 Share Posted August 31, 2010 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? Quote Link to comment Share on other sites More sharing options...
dean7 Posted August 31, 2010 Author Share Posted August 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 What is the name of the file that code is in? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 31, 2010 Share Posted August 31, 2010 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? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 31, 2010 Share Posted August 31, 2010 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="" Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
dean7 Posted August 31, 2010 Author Share Posted August 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 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? Quote Link to comment Share on other sites More sharing options...
dean7 Posted August 31, 2010 Author Share Posted August 31, 2010 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.. Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
dean7 Posted August 31, 2010 Author Share Posted August 31, 2010 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 Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 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? Quote Link to comment Share on other sites More sharing options...
dean7 Posted August 31, 2010 Author Share Posted August 31, 2010 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 Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 Try placing print statements right before all of your exit() calls to see if one of them is getting executed accidentally. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.