...

View Full Version : Stupid Errors



NightFlyer
06-13-2008, 08:01 PM
Every single time I try to login it gives me that echo "Sorry"
login_success.php

<?php require("config.php"); require_once("include/menu.php"); ?>
<div id="container">
<div id="content">
<script type="text/javascript">
<!--
function delayer(){
window.location = "../javascriptredirect.php"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 3000)">
<h2 >&nbsp;</h2>
<p>&nbsp;</p>
<div align="center">
<?php

if ($level =="1" ) { echo "You are now being logged in, as a User"; }
else {
if ($level =="2" ) { echo "You are now being logged in, as a Moderator"; }
else {
if ($level =="3" ) { echo "You are now being logged in, as a Super Moderator"; }
else {
if ($level =="4" ) { echo "You are now being logged in, as an Administrator"; }
else { echo "Sorry"; }}}}

?>


config.php


<?php session_start();
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("maindb") or die(mysql_error());


$result = mysql_query("SELECT level FROM members WHERE username='$username'");
$row = mysql_fetch_assoc($result); // The results are stored in an sql result array -we need to extract them
$level = $row['level']; // Since we extracted it into an array, get the correct index of the array
if ($level == "0" ) {

}else {
if ($level == "2" ) {


}else {
if ($level == "3" ) {


}else {

if ($level == "4" ) {


}else {

}
}
}
} ?>

I want the login_success.php page to work. I just posted config.php because maybe it has to do with that. PLEASE help me.

mr e
06-13-2008, 08:05 PM
Try echo'ing the variables in different places to make sure they're set correctly (like when they're pulled from the database)

NightFlyer
06-13-2008, 08:06 PM
It still doesn't work.

malfist
06-13-2008, 08:07 PM
What happens with this?


<?php session_start();
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("maindb") or die(mysql_error());


$result = mysql_query("SELECT level FROM members WHERE username='$username'");
$row = mysql_fetch_array($result); // The results are stored in an sql result array -we need to extract them
print_r($row);
$level = $row['level']; // Since we extracted it into an array, get the correct index of the array
if ($level == "0" ) {

}else {
if ($level == "2" ) {


}else {
if ($level == "3" ) {


}else {

if ($level == "4" ) {


}else {

}
}
}
} ?>

NightFlyer
06-13-2008, 08:10 PM
That doesn't work either.

malfist
06-13-2008, 08:11 PM
What does the print_r say?

malfist
06-13-2008, 08:12 PM
This is dangerous:


$result = mysql_query("SELECT level FROM members WHERE username='$username'");


What happens if the user enters SQL instead of a username? Like '; DROP DATABASE;

NightFlyer
06-13-2008, 08:13 PM
Still don't work.

malfist
06-13-2008, 08:15 PM
What does the print_r echo?
print_r doesn't do anything except echo variables, such as arrays.

tomws
06-13-2008, 08:24 PM
Same as before: you're not assigning a value to $username before you use it.

malfist
06-13-2008, 08:28 PM
Same as before: you're not assigning a value to $username before you use it.

Unless he's got it set so that $username is the same as $_POST['username'].

What does echo $username show?

mr e
06-13-2008, 08:49 PM
Didn't we have this problem in another thread already?

@NightFlyer Echo. Your. Variables.

Seriously, we can't walk you through every single step of debugging a script, you're gonna have to learn how to do some of it on your own, these past 5 or so threads for example, you keep having very similar problems that you might not otherwise

NightFlyer
06-13-2008, 08:51 PM
I have got it to work as I forgot my variable $username. Thank you guys.

tomws
06-13-2008, 08:52 PM
Didn't we have this problem in another thread already?

You can teach the technique of debugging, but you can teach the desire to debug.

malfist
06-13-2008, 08:56 PM
You can teach the technique of debugging, but you can teach the desire to debug.

Leave off, everybody makes mistakes. Especially people new to things. If he's not familiar with OOP debugging he's not going to do it. It's not his fault, he just needs to learn. Insulting him isn't a way to produce debugging results, just the same as telling a teenager they can't do something because they'll do it anyway.

CFMaBiSmAd
06-13-2008, 09:09 PM
This is dangerous:


$result = mysql_query("SELECT level FROM members WHERE username='$username'");


What happens if the user enters SQL instead of a username? Like '; DROP DATABASE;The php mysql client library does not support multiple queries separated by ; So, while sql injection within a single query is possible in code that does not escape data, executing multiple queries is not.

NightFlyer
06-13-2008, 09:10 PM
It's ok malfist. I know what tom means ;)

tomws
06-13-2008, 09:37 PM
Leave off, everybody makes mistakes. Especially people new to things. If he's not familiar with OOP debugging he's not going to do it. It's not his fault, he just needs to learn. Insulting him isn't a way to produce debugging results, just the same as telling a teenager they can't do something because they'll do it anyway.

1. Mistakes are tolerable - I have more than my fair share and freely admit it.

2. New coders are tolerable - hence my comment about teaching the technique and a goodly portion of my post history.

3. OOP hasn't entered into this dicussion at all, let alone the debugging of it.

4. If a coder doesn't understand a technique, it is his/her fault - whose else would it be?

Anyway, the point is the desire to put the effort into debugging, not the activity itself or the failure to produce usable results (which also was an issue here).

But you're welcome to tilt at as many windmills as you wish. Read through my post history and give it another shot.

malfist
06-14-2008, 12:03 AM
1. Mistakes are tolerable - I have more than my fair share and freely admit it.

2. New coders are tolerable - hence my comment about teaching the technique and a goodly portion of my post history.

3. OOP hasn't entered into this dicussion at all, let alone the debugging of it.

OOP did not, but OOP was probably the wrong word choice, a fully featured language such as java, python, C, PHP, Haskell, etc require different debugging styles than non-real or non-fully developed languages such as HTML, XML, CSS.



4. If a coder doesn't understand a technique, it is his/her fault - whose else would it be?

No it's not their fault. If and only if they have encountered the technique and remain deliberately ignorant of it does it become their fault. If they are learning or not yet grasping the technique, it is not their fault. Was it my fault I didn't now abstraction patterns with I first started writing Hello World programs in Java?

edit: I know I have no reason to argue anymore but I do enjoy it.

Ludwig
06-14-2008, 12:06 AM
Gees tomws, Why are you acting like this?

mr e
06-14-2008, 02:55 AM
In tomws's defense, NightFlyer has started about 5 different threads over the last few days in which we have all given him advice that could have been easily avoided had he utilized even simple debugging techniques, such as echo'ing variables.

I understand he may be new to the language, and methods of debugging it, but not only have we needed to ask him multiple times to echo variables and such, but he repeatedly comes back with short one line responses that seemingly indicate he doesn't want to perform the work himself, but rather have it given to him.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum