 |
|
 |
|
Next: Please, endorse my new php class library and get ..
|
| Author |
Message |
External

Since: May 19, 2008 Posts: 2
|
(Msg. 1) Posted: Mon May 19, 2008 4:36 am
Post subject: problems with login script Archived from groups: comp>lang>php (more info?)
|
|
|
Hi, I can't get this script to work.
I've used this exact script on other places and it works, but now i
get this error.
<code> Warning: mysql_fetch_array(): supplied argument is not a valid
MySQL result resource in C:\xampp\htdocs\uploads\login_script.php on
line 15 </code>
I can't see what is wrong.
Here is the script.
<code>
<?php
session_start();
$anvnamn = $_POST['usr'];
$losenord = $_POST['pwd'];
include "dbconnect.php";
$anv2 = mysql_real_escape_string($anvnamn, $dbconnect);
$los2 = mysql_real_escape_string($losenord, $dbconnect);
$sqlfraga = "SELECT anvnamn FROM administrator WHERE anvnamn = '" .
$anvnamn . "' AND losen = '" . $losenord . "'";
$res = mysql_query($sqlfraga, $dbconnect);
if($rad = mysql_fetch_array($res))
{
$_SESSION['logged_in_admin'] = true;
}
else
{
$_SESSION['logged_in_admin'] = false;
}
?>
<html>
<body>
<?php
if($_SESSION['logged_in_admin'])
{
echo("You are logged in");
include('index.php');
}
else
{
echo ("go away");
}
?>
</body>
</html>
</code> >> Stay informed about: problems with login script |
|
| Back to top |
|
 |  |
External

Since: May 19, 2008 Posts: 10
|
(Msg. 2) Posted: Mon May 19, 2008 4:59 am
Post subject: Re: problems with login script [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On May 19, 1:36 pm, wrote:
> <code> Warning: mysql_fetch_array(): supplied argument is not a valid
> MySQL result resource in C:\xampp\htdocs\uploads\login_script.php on
> line 15 </code>
>
> $res = mysql_query($sqlfraga, $dbconnect);
> if($rad = mysql_fetch_array($res))
When the query fails, mysql_query() returns false, which results in
the error message you wrote. I am not sure if this is the case in your
situation, because this would also print a warning. Check the output
of mysql_query() and use mysql_error() to get the error message. >> Stay informed about: problems with login script |
|
| Back to top |
|
 |  |
External

Since: May 19, 2008 Posts: 2
|
(Msg. 3) Posted: Mon May 19, 2008 5:40 am
Post subject: Re: problems with login script [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On May 19, 2:13 pm, "Álvaro G. Vicario"
wrote:
> escribió:
>
> > Hi, I can't get this script to work.
> > I've used this exact script on other places and it works, but now i
> > get this error.
>
> > <code> Warning: mysql_fetch_array(): supplied argument is not a valid
> > MySQL result resource in C:\xampp\htdocs\uploads\login_script.php on
> > line 15 </code>
>
> > I can't see what is wrong.
>
> Speaking in plain English, this error message means that you can't fetch
> rows from $res because the database query failed. So you need to check
> whether the query fails or not:
>
> > $res = mysql_query($sqlfraga, $dbconnect);
>
> if(!$res){
> // Error: log it, abort or whatever
> echo 'Query failed: ' . mysql_error();
>
> }else{
> // Read rows
> }
>
> I also recommend you to enable full error reporting (at least in your
> dev box). Edit your php.ini file or add this to the top of the script:
>
> ini_set('display_errors', 1);
> error_reporting(E_ALL);
>
> --
> --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web:http://bits.demogracia.com
> -- Mi web de humor al baño María:http://www.demogracia.com
> --
tanks for the help all of you guys.. the escaping being wrong i was
already aware of, i was in a bit of hurry when i set them up and i saw
that it was wrong just after posting this...
anyways the problem was that i named the table administrators in the
database and i wrote administrator in the querry, so all i really
needed was an "s"... >> Stay informed about: problems with login script |
|
| Back to top |
|
 |  |
External

Since: Apr 06, 2005 Posts: 2
|
(Msg. 4) Posted: Mon May 19, 2008 1:05 pm
Post subject: Re: problems with login script [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
wrote:
> Hi, I can't get this script to work.
> I've used this exact script on other places and it works, but now i
> get this error.
>
> <code> Warning: mysql_fetch_array(): supplied argument is not a valid
> MySQL result resource in C:\xampp\htdocs\uploads\login_script.php on
> line 15 </code>
>
> I can't see what is wrong.
> Here is the script.
>
> <code>
> <?php
> session_start();
> $anvnamn = $_POST['usr'];
> $losenord = $_POST['pwd'];
>
> include "dbconnect.php";
>
> $anv2 = mysql_real_escape_string($anvnamn, $dbconnect);
> $los2 = mysql_real_escape_string($losenord, $dbconnect);
You create some escaped versions of the $_POST data...
> $sqlfraga = "SELECT anvnamn FROM administrator WHERE anvnamn = '" .
> $anvnamn . "' AND losen = '" . $losenord . "'";
.... but then fail to use them (SQL injection alert!).
> $res = mysql_query($sqlfraga, $dbconnect);
Then fail to check whether $res is FALSE, which could be the case if
there was an issue with rights to the database.
> if($rad = mysql_fetch_array($res))
Which would cause this to error as described.
So, the error said that $res wasn't valid, so why didn't you check what
was being used? Simple debugging...
Robin >> Stay informed about: problems with login script |
|
| Back to top |
|
 |  |
External

Since: Sep 02, 2007 Posts: 210
|
(Msg. 5) Posted: Mon May 19, 2008 2:07 pm
Post subject: Re: problems with login script [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Mon, 19 May 2008 13:36:24 +0200, wrote:
> Hi, I can't get this script to work.
> I've used this exact script on other places and it works, but now i
> get this error.
>
> <code> Warning: mysql_fetch_array(): supplied argument is not a valid
> MySQL result resource in C:\xampp\htdocs\uploads\login_script.php on
> line 15 </code>
>
> I can't see what is wrong.
> Here is the script.
>
> <code>
> <?php
> session_start();
> $anvnamn = $_POST['usr'];
> $losenord = $_POST['pwd'];
>
> include "dbconnect.php";
>
> $anv2 = mysql_real_escape_string($anvnamn, $dbconnect);
> $los2 = mysql_real_escape_string($losenord, $dbconnect);
Proper escaping and then:
> $sqlfraga = "SELECT anvnamn FROM administrator WHERE anvnamn = '" ..
> $anvnamn . "' AND losen = '" . $losenord . "'";
.... using the unescaped variables!
You, my friend, are vulnerable to SQL injection. Use the $avn2 & $los2
variables in the query, that's why you escape()d them...
If you still have the same problem, echo $sqlfraga & mysql_error() to the
screen and check what's wrong with the query.
--
Rik Wasmus
....spamrun finished >> Stay informed about: problems with login script |
|
| Back to top |
|
 |  |
External

Since: Sep 02, 2007 Posts: 210
|
(Msg. 6) Posted: Mon May 19, 2008 2:08 pm
Post subject: Re: problems with login script [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Mon, 19 May 2008 14:05:55 +0200, Robin wrote:
> wrote:
>> Hi, I can't get this script to work.
>> I've used this exact script on other places and it works, but now i
>> get this error.
>> <code> Warning: mysql_fetch_array(): supplied argument is not a valid
>> MySQL result resource in C:\xampp\htdocs\uploads\login_script.php on
>> line 15 </code>
>> I can't see what is wrong.
>> Here is the script.
>> <code>
>> <?php
>> session_start();
>> $anvnamn = $_POST['usr'];
>> $losenord = $_POST['pwd'];
>> include "dbconnect.php";
>> $anv2 = mysql_real_escape_string($anvnamn, $dbconnect);
>> $los2 = mysql_real_escape_string($losenord, $dbconnect);
>
> You create some escaped versions of the $_POST data...
>
>> $sqlfraga = "SELECT anvnamn FROM administrator WHERE anvnamn = '" .
>> $anvnamn . "' AND losen = '" . $losenord . "'";
>
> ... but then fail to use them (SQL injection alert!).
Hehe, you beat me to it, with even more or less the same format/wording
--
Rik Wasmus
....spamrun finished >> Stay informed about: problems with login script |
|
| Back to top |
|
 |  |
External

Since: Apr 10, 2008 Posts: 491
|
(Msg. 7) Posted: Mon May 19, 2008 2:13 pm
Post subject: Re: problems with login script [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
escribió:
> Hi, I can't get this script to work.
> I've used this exact script on other places and it works, but now i
> get this error.
>
> <code> Warning: mysql_fetch_array(): supplied argument is not a valid
> MySQL result resource in C:\xampp\htdocs\uploads\login_script.php on
> line 15 </code>
>
> I can't see what is wrong.
Speaking in plain English, this error message means that you can't fetch
rows from $res because the database query failed. So you need to check
whether the query fails or not:
> $res = mysql_query($sqlfraga, $dbconnect);
if(!$res){
// Error: log it, abort or whatever
echo 'Query failed: ' . mysql_error();
}else{
// Read rows
}
I also recommend you to enable full error reporting (at least in your
dev box). Edit your php.ini file or add this to the top of the script:
ini_set('display_errors', 1);
error_reporting(E_ALL);
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
-- >> Stay informed about: problems with login script |
|
| Back to top |
|
 |  |
| Related Topics: | OWA: 'Posting a Login' From Outside Script? - I am just wondering if anyone here can help with a problem that we have here. We have a PHP based website/application that has a user login that is connected to our AD setup. This works fine. Obviously their usernames and passwords are common to their..
Problems of PHP script running Perl program with Spreadshe.. - My php script is to call perl scipt which makes use of Spreadsheet::ParseExcel module to parse Excel file. I am able to launch php script from command line so that perl script can run and properly parse Excel file. However, when I put php script on serve...
how to create 'remember login' functionality during login - Hi! could anyone give me some clue that how to create 'remember login' functionality during login Thanks Sukalyan
Multiple login without db - I'm newbie. Just wonder, after googling for several hours: is it impossible to make a login script for, say, three different users and, after successfull login with username and password, redirect them to their destination (totally three destinations,...
Get Windows login - Hi! I was given a task to develop a php based application. All well, but now my boss wants me to make it more "user friendly" in a manner that they won't have to write in their usernames and passwords, which they already have too many. I figu... |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
 |
|
|