The “changeUserRole” action always leads me to localhost… which is xampp index.php, instead of myproject/index.php?setting=userlist.
I don’t understand why as I have implemented the very same technique in a different file for different settings.
The file it is supposed to redirect to is action_changeuserrole.php which runs an SQL query and redirects back to this file, only without the parameters.
function showUserlistManagement() {
if (@$_GET['action'] == "addUser") {
require_once('actions/userlist/adduser.php');
}
else if (@$_GET['action'] == "changeUserRole" ) {
require_once('actions/userlist/action_changeuserrole.php');
}
else {
echo "<a href='?setting=userlist&action=addUser'><button>Add User</button></a>";
$i = 0;
$sql = "SELECT doctorID, username, isAdmin FROM doctor ORDER BY isAdmin DESC";
$result = query($sql);
echo "<table border='1'>";
while ($row = mysql_fetch_array($result)) {
$i = $i + 1;
echo "<tr><td>" . $i . "</td><td>" . $row['username'] . "</td><td>" . isAdminText($row['isAdmin']) . "</td><td><a href='?setting=userlist&action=changeUserRole&userID=" . $row['doctorID'] . "&userRole=" . $row['isAdmin'] . "'><button>" . changeUserRoleButton($row['isAdmin']) . "</button></a></td></tr>";
}
}
function isAdminText($isAdmin) {
if ($isAdmin) {
return "admin";
}
else return "user";
}
function changeUserRoleButton($isAdmin) {
if ($isAdmin) {
return 'Demote';
}
else return 'Promote';
}
}
The action_changeuserrole.php file :
<?php
//$sql = "UPDATE doctor SET (isAdmin = '1') WHERE doctorID = " . $_GET['userID'];
//$result = query($sql);
?>
<meta http-equiv='refresh' content='0; URL=../../index.php?setting=userlist'>
difficult to understand what you are asking and what exactly is happening in your code, but maybe this will help.
since the path is relative, where it leads you would depend on what the current url is (or base tag value).
if your url is:
foo/bar/something/something/test.php../../index.phpwould then lead to:foo/bar/index.phpon the other hand, if your url is:
foo/bar/test.php../../index.phpwould then lead to:index.phpTo help mitigate this, some people use the
<base>tag in their HTML. This tag lets you specify a base URL that all relative URLs will use to calculate a final path from. Not 100% sure if this works with meta refreshes. You will have to test.