First is about a if statement that behaves well not like I expect it, maybe i did something wrong but if so I can't see it.
The other is that when I send the form I have in the page it doesn't send the browser to the page specified in action like it should, this isn't the first form I've done and I've never had these errors.
Ill just post the code in question and go on after that... If anyone would want it in plain HTML, what you get when viewing the page source in a browser just ask, I've checked the code that way and everything is right as far as I see...
Code might be a little rough, just threw it together quite quickly last night, wont clean it and make it nice until everything works.
OK, so you can probably see the if statement, it's early in the code and commented out, the problem is that even if $_SESSION['usertype'] is admin or moderator it still executes the code, if I remove one of them and just checks for one of them it works, I've done if statements with more than one condition before and it worked, can't it be done when checking if something is not equal or what? What am I missing here? As you might see in the next if statement in there it works if I separate them but don't like to do it like that...
And the second problem, the form, when I click the submit button the browser should go on to "updateuser.php" but it wont, it just stays at the same page and ads a lot of querystrings to the URL, for example "/edituser.php?id=4&username=sergh&name=fgbfg&password=bggh&email=mail%40test.com&usertype=standard&submit=Spara"
Question
Leonick
So as the title say, two problems here...
First is about a if statement that behaves well not like I expect it, maybe i did something wrong but if so I can't see it.
The other is that when I send the form I have in the page it doesn't send the browser to the page specified in action like it should, this isn't the first form I've done and I've never had these errors.
Ill just post the code in question and go on after that... If anyone would want it in plain HTML, what you get when viewing the page source in a browser just ask, I've checked the code that way and everything is right as far as I see...
Code might be a little rough, just threw it together quite quickly last night, wont clean it and make it nice until everything works.
<?php session_start(); include("connect.inc"); $QStr = $_GET['user']; $user=mysql_fetch_array(mysql_query("select * from userlist where username='". $QStr ."'")); if(isset($_SESSION['username'])) { /*if($_SESSION['usertype']!="admin"||$_SESSION['usertype']!="moderator") { if($QStr!=$_SESSION['username']) { mysql_close($con); header('location: index.php'); } } }*/ if($_SESSION['usertype']!="admin") { if($_SESSION['usertype']!="moderator") { if($QStr!=$_SESSION['username']) { mysql_close($con); header('location: index.php'); } } } if($_SESSION['usertype']=="moderator") { if($user['usertype']=="admin") { mysql_close($con); header('location: index.php'); } } } else { mysql_close($con); header('location: index.php'); } echo "<html> <head> <link rel=\"stylesheet\" type=\"text/css\" title=\"standard\" href=\"css.css\"/> <style type=\"text/css\"> body { margin-top:10px; margin-left:60px; margin-right:60px;} </style> </head> <body>"; if($_SESSION['usertype']=="admin"||$_SESSION['usertype']=="moderator") { echo "Admintools liked remove and block will be here" } echo "<form> <form action=\"updateuser.php\" method=\"post\"> <input type=\"hidden\" name=\"id\" value=\"". $user['ID'] ."\">"; if($_SESSION['usertype']=="admin") { echo "Anv?ndarnamn: <input type=\"text\" name=\"username\" value=\"". $user['username'] ."\" style='width:150px;'/><br/>"; } if($_SESSION['usertype']!="admin") { echo "Anv?ndarnamn: <input type=\"text\" name=\"username\" value=\"". $user['username'] ."\" readonly><br/>"; } echo "F?rnamn: <input type=\"text\" name=\"name\" value=\"". $user['name'] ."\" style='width:150px;'/><br/> L?senord: <input type=\"text\" name=\"password\" value=\"". $user['password'] ."\" style='width:150px;'/><br/> Email: <input type=\"text\" name=\"email\" value=\"". $user['email'] ."\" style='width:150px;'/><br/>"; if($_SESSION['usertype']=="admin"||$_SESSION['usertype']=="moderator") { echo "Anv?ndartyp: <input type=\"text\" name=\"usertype\" value=\"". $user['usertype'] ."\" style='width:150px;'/><br/>"; } else{ echo "<input type=\"hidden\" name=\"usertype\" value=\"". $user['usertype'] ."\"><br/>"; } echo "<input type=\"submit\" name=\"submit\" value=\"Spara\"> <input type=\"button\" name=\"cancel\" value=\"Avbryt\" onclick=Javascript:history.go(-1)> </form> </body> </html>"; ?>OK, so you can probably see the if statement, it's early in the code and commented out, the problem is that even if $_SESSION['usertype'] is admin or moderator it still executes the code, if I remove one of them and just checks for one of them it works, I've done if statements with more than one condition before and it worked, can't it be done when checking if something is not equal or what? What am I missing here? As you might see in the next if statement in there it works if I separate them but don't like to do it like that...
And the second problem, the form, when I click the submit button the browser should go on to "updateuser.php" but it wont, it just stays at the same page and ads a lot of querystrings to the URL, for example "/edituser.php?id=4&username=sergh&name=fgbfg&password=bggh&email=mail%40test.com&usertype=standard&submit=Spara"
So anyone who can help me figure this out?
Link to comment
Share on other sites
3 answers to this question
Recommended Posts