473,662 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems with login script

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.

<codeWarning: mysql_fetch_arr ay(): 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_esca pe_string($anvn amn, $dbconnect);
$los2 = mysql_real_esca pe_string($lose nord, $dbconnect);

$sqlfraga = "SELECT anvnamn FROM administrator WHERE anvnamn = '" .
$anvnamn . "' AND losen = '" . $losenord . "'";
$res = mysql_query($sq lfraga, $dbconnect);

if($rad = mysql_fetch_arr ay($res))
{
$_SESSION['logged_in_admi n'] = true;
}
else
{
$_SESSION['logged_in_admi n'] = false;
}
?>
<html>
<body>
<?php
if($_SESSION['logged_in_admi n'])
{
echo("You are logged in");
include('index. php');

}
else
{
echo ("go away");
}
?>
</body>
</html>
</code>
Jun 2 '08 #1
6 1316
On May 19, 1:36*pm, morph.1...@gmai l.com wrote:
<codeWarning: mysql_fetch_arr ay(): supplied argument is not a valid
MySQL result resource in C:\xampp\htdocs \uploads\login_ script.php on
line 15 </code>

$res = mysql_query($sq lfraga, $dbconnect);
if($rad = mysql_fetch_arr ay($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.

Jun 2 '08 #2
mo********@gmai l.com 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.

<codeWarning: mysql_fetch_arr ay(): 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_esca pe_string($anvn amn, $dbconnect);
$los2 = mysql_real_esca pe_string($lose nord, $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($sq lfraga, $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_arr ay($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
Jun 2 '08 #3
On Mon, 19 May 2008 13:36:24 +0200, <mo********@gma il.comwrote:
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.

<codeWarning: mysql_fetch_arr ay(): 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_esca pe_string($anvn amn, $dbconnect);
$los2 = mysql_real_esca pe_string($lose nord, $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
Jun 2 '08 #4
On Mon, 19 May 2008 14:05:55 +0200, Robin <an**@somewhere .comwrote:
mo********@gmai l.com 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.
<codeWarning: mysql_fetch_arr ay(): 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_esca pe_string($anvn amn, $dbconnect);
$los2 = mysql_real_esca pe_string($lose nord, $dbconnect);

You create some escaped versions of the $_POST data...
>$sqlfraga = "SELECT anvnamn FROM administrator WHERE anvnamn = '"
Jun 2 '08 #5
mo********@gmai l.com 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.

<codeWarning: mysql_fetch_arr ay(): 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($sq lfraga, $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('displa y_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
--
Jun 2 '08 #6
On May 19, 2:13 pm, "Álvaro G. Vicario"
<alvaroNOSPAMTH A...@demogracia .comwrote:
morph.1...@gmai l.com 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.
<codeWarning: mysql_fetch_arr ay(): 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($sq lfraga, $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('displa y_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"...
Jun 2 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4573
by: Manu J | last post by:
Hi, i have a login script which makes use of sessions. Login script *********** session_start() ..... ..... ....
3
2863
by: koolyio | last post by:
Hey, could you please tell me what is wrong with my login script. I just started learning php. CODE: login.php <? session_start(); header("Cache-Control: private"); ?>
3
2408
by: nao921 | last post by:
Hi everyone, I am currently involved in a project that involves a windows client program written in delphi and a web application written in php. I have made several php pages for the delphi program to do requests via the http component from INDY. the problems I am having are: 1) the first request from delphi app to php web app is the authenication. In which user sends username + password to the php app. If authenication is valid, a...
5
1930
by: simo | last post by:
I've written a pretty big wxPython script, and I thought I'd split the source into a few files. I'm going to have a main.py file which includes global defs, wxApp initialisation code, mainWindow() etc. and then each file will include a GUI class (which just happen to be a wxNotebook tab each). I'm having trouble accessing the imported classes though. For example I have login.py which contains something like this:
0
4548
by: Ira Lee | last post by:
Hi. I'm having a bit of trouble using a Perl script that will login to a secure website... and then access subsequent pages with a cookie. This works when accessing manually via the browser (Konqueror) which then accepts the cookie and allows me to login to subsequent pages with the valid cookie. It appears that the HTTP/SSLeay installation is working fine since no errors come up when I access "https://" directives. I just haven't been...
9
1675
by: Graham Campbell | last post by:
I have a login script to a website where a user logs in through a standard webform with a username and password that needs to be validated. My problem is that IE6 doesn't seem to pick up on valid username/password combinations and instead of forwarding the user to the next page dumps them back at the login page. My verification script is below: <% Response.CacheControl = "no-cache"
4
1611
by: Tamer Higazi | last post by:
Hi! I wrote a small script setting a cookie.... but nothing is being set. What could be the problem?! Did I make something wrong?! One script is used to ask for the cookie and the other one shows the displayed variable in a string only! But if I look at Firefox in the cookie cache if the variables are set... I didn't find anything. what could be the problem?! Apache 2.0.54 with PHP 5.1 RC1 on Gentoo Linux 2005.1
0
3221
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs converted/developed with VB.NET. What I want from debugging is to be able to step into the methods in the DLLs called from ASP scripts using Visual Studio .NET. Background: For typical script debugging issues, you can read and follow the two documents on...
2
1493
by: Assimalyst | last post by:
Hi, I am creating a website where i want to allow some webforms to be accessible to all users, and those in a subdirectory available only to authenticated users. I have created a script to authenticate users from a stored sql database from a login page login.aspx. private void Submit1_ServerClick(object sender, System.EventArgs e)
0
1318
by: kang jia | last post by:
hi i have small problems occurred in my login function, which i use Django to build, in my template which is login.html, the code is like the following: <html> <head> <title>Login</title>
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.