473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

mysql/php error message?

Hello

I get the following error

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in path/user-groups.php on line 25" (line 25 is the
one with a *)

with

@require(dirname(__FILE__) . '/../../config_php/config.php');

$query ="select * from users where " . "user_name " ."like" . "%" .
$_POST['username'] . "%";

$link = mysql_connect(
$conf['sql']['host'],
$conf['sql']['user'],
$conf['sql']['pass']
) or die ("cannot make connection to {$conf['sql']['db']}");

if (mysql_select_db($conf['sql']['db'],$link)) {

$result = mysql_query($query, $link);

while ($row = mysql_fetch_array($result)) { //*
echo $row['user_name'] . " " . $row['group1'] ."<br>";
}
}
why?!

is it because there is only 1 record for each user_name?

Cheers

Geoff
Aug 11 '08 #1
4 1216
Geoff Cox wrote:
Hello

I get the following error

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in path/user-groups.php on line 25" (line 25 is the
one with a *)

with

@require(dirname(__FILE__) . '/../../config_php/config.php');

$query ="select * from users where " . "user_name " ."like" . "%" .
$_POST['username'] . "%";

$link = mysql_connect(
$conf['sql']['host'],
$conf['sql']['user'],
$conf['sql']['pass']
) or die ("cannot make connection to {$conf['sql']['db']}");

if (mysql_select_db($conf['sql']['db'],$link)) {

$result = mysql_query($query, $link);

while ($row = mysql_fetch_array($result)) { //*
echo $row['user_name'] . " " . $row['group1'] ."<br>";
}
}
why?!

is it because there is only 1 record for each user_name?

Cheers

Geoff
No, it's because your mysql_query had an error.

ALWAYS check the results of ANY mysql call. In this case:

if (!$result)
echo mysql_error();

will show you your problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 11 '08 #2
Geoff Cox <gc**@freeuk.notcomwrote:
Hello

I get the following error

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in path/user-groups.php on line 25" (line 25 is the
one with a *)

with

@require(dirname(__FILE__) . '/../../config_php/config.php');

$query ="select * from users where " . "user_name " ."like" . "%" .
$_POST['username'] . "%";

$link = mysql_connect(
$conf['sql']['host'],
$conf['sql']['user'],
$conf['sql']['pass']
) or die ("cannot make connection to {$conf['sql']['db']}");

if (mysql_select_db($conf['sql']['db'],$link)) {

$result = mysql_query($query, $link);

while ($row = mysql_fetch_array($result)) { //*
echo $row['user_name'] . " " . $row['group1'] ."<br>";
}
}
Two observations: (1) like '%foo%' (the apostrophes are required).
You show: like%foo%
(2) Dangerous to use raw POST in a query, see:
http://php.net/function.mysql-real-escape-string

--
Charles
Aug 12 '08 #3
On Mon, 11 Aug 2008 19:37:38 -0400, Jerry Stuckle
<js*******@attglobal.netwrote:
>Geoff Cox wrote:
>Hello

I get the following error

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in path/user-groups.php on line 25" (line 25 is the
one with a *)

with

@require(dirname(__FILE__) . '/../../config_php/config.php');

$query ="select * from users where " . "user_name " ."like" . "%" .
$_POST['username'] . "%";

$link = mysql_connect(
$conf['sql']['host'],
$conf['sql']['user'],
$conf['sql']['pass']
) or die ("cannot make connection to {$conf['sql']['db']}");

if (mysql_select_db($conf['sql']['db'],$link)) {

$result = mysql_query($query, $link);

while ($row = mysql_fetch_array($result)) { //*
echo $row['user_name'] . " " . $row['group1'] ."<br>";
}
}
why?!

is it because there is only 1 record for each user_name?

Cheers

Geoff

No, it's because your mysql_query had an error.

ALWAYS check the results of ANY mysql call. In this case:

if (!$result)
echo mysql_error();

will show you your problem.
it did indeed!

thanks Jerry.

Cheers

Geoff
Aug 12 '08 #4
On Mon, 11 Aug 2008 23:35:10 -0500, Charles Polisher
<cp*****@nonesuch.comwrote:
>Geoff Cox <gc**@freeuk.notcomwrote:
>Hello

I get the following error

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in path/user-groups.php on line 25" (line 25 is the
one with a *)

with

@require(dirname(__FILE__) . '/../../config_php/config.php');

$query ="select * from users where " . "user_name " ."like" . "%" .
$_POST['username'] . "%";

$link = mysql_connect(
$conf['sql']['host'],
$conf['sql']['user'],
$conf['sql']['pass']
) or die ("cannot make connection to {$conf['sql']['db']}");

if (mysql_select_db($conf['sql']['db'],$link)) {

$result = mysql_query($query, $link);

while ($row = mysql_fetch_array($result)) { //*
echo $row['user_name'] . " " . $row['group1'] ."<br>";
}
}

Two observations: (1) like '%foo%' (the apostrophes are required).
You show: like%foo%
(2) Dangerous to use raw POST in a query, see:
http://php.net/function.mysql-real-escape-string
thanks for both ideas - is working now!

Cheers

Geoff
Aug 12 '08 #5

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

Similar topics

0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Stefan Hinz | last post by:
Degan, jumping in to try and solve some problems that look pretty obvious to me ... > #options for default service (mysqld2) > (mysqld2) It should be , not (mysqld2).
0
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to...
0
by: Annie Xie | last post by:
1> anyone has a compiled tarball for mysql new version (-4.0 up) for solaris 2.6 can be shared? The OS was patched latest. 2> I'm trying build it, configure w/o any problem. However, when dong...
2
by: jmlynn | last post by:
Help! I installed MySQL 4.0.20C and it works if I started it with mysqld --console However, if I do the following: mysqld --install net start MySQL
4
by: Adam Smith | last post by:
I have a dedicated server running 'FreeBSD 4.9 STABLE' at a hosting site. They have done some default installations, presumably from the CVS ports package ??. Herein lies the problem, "I do not...
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
18
by: Bruce A. Julseth | last post by:
I have the following code $Host = "localhost"; $User = "Fred"; $Database = "house"; $Password = "mypw" echo "before mysqli<br />Host: " . $Host . "<br />" . $User . "<br />" . $Database;
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.