473,395 Members | 1,815 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,395 software developers and data experts.

mysql_num_rows HELP

Hi

Sorry for my terreble english.

On my local (win) comp i have apache+mysql+php 4.05
I'm counting rows using mysql_num_rows function, and everything works fine.
When i upload php file on server it says:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /home/optikara/public_html/crosun/izn/insert_form.php on line 80
Server runs php 5.0.5

Code is:
--------------------------
//connect to database code goes here

$result_v_smjestaj = mysql_query("select * from v_smjestaja order by
v_smjestaja_naziv ASC", $db);
// some other html code goes here

if (mysql_num_rows($result_v_smjestaj)) {
print "<select name=\"v_smjestaja\">\n";
while ($qry = mysql_fetch_array($result_v_smjestaj)) {
print "<option
value=\"$qry[id_smjestaja]\">$qry[v_smjestaja_naziv]</option>";
}
print "</select>\n";
}
--------------------------

On my local comp this works. Plz any solution, in plain simple code:)))
tnx in advance.
Dejan

Apr 3 '06 #1
7 1901
Dejan wrote:
Hi

Sorry for my terreble english.

On my local (win) comp i have apache+mysql+php 4.05
I'm counting rows using mysql_num_rows function, and everything works fine.
When i upload php file on server it says:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /home/optikara/public_html/crosun/izn/insert_form.php on line 80
Server runs php 5.0.5

Code is:
--------------------------
//connect to database code goes here

$result_v_smjestaj = mysql_query("select * from v_smjestaja order by
v_smjestaja_naziv ASC", $db);
// some other html code goes here

if (mysql_num_rows($result_v_smjestaj)) {
print "<select name=\"v_smjestaja\">\n";
while ($qry = mysql_fetch_array($result_v_smjestaj)) {
print "<option
value=\"$qry[id_smjestaja]\">$qry[v_smjestaja_naziv]</option>";
}
print "</select>\n";
}
--------------------------

On my local comp this works. Plz any solution, in plain simple code:)))
tnx in advance.
Dejan


1. Always check the result from mysql_query (and all similar mysql_ calls).
2. When it fails, check the error message with mysql_error().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 3 '06 #2
Some hints:
- You don't need to pass your database connection to mysql_query() (2nd
argument)
- When sending queries to your database *always* check for errors using
sth. like
mysql_query('...') or die(mysql_error());
- Use shorter variable names to avoid typing errors
- Use single quotes ('...') for HTML if you don't like escaping all the
double quotes too much. ;)

Apr 3 '06 #3
milahu wrote:
Some hints:
- You don't need to pass your database connection to mysql_query() (2nd
argument)
- When sending queries to your database *always* check for errors using
sth. like
mysql_query('...') or die(mysql_error());
- Use shorter variable names to avoid typing errors
- Use single quotes ('...') for HTML if you don't like escaping all the
double quotes too much. ;)


No, you don't *need* to pass the database connection. But it's a good idea to
do so. And it never hurts.

If you don't, PHP will use the last opened connection. That may be good now -
but changes in the code at a later date may change that. Now you've added a bug
which can be hard to fix (it fails in an area of code you didn't touch).

Also, I prefer *longer* more descriptive variable names. I don't understand
Dejan's native language, but these variables don't look exactly random to me.
I'm sure they mean something to him.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 3 '06 #4
Write your code like this:

$query = "....";
$result = mysql_query($query);
if($result) {
$num_rows = mysql_num_rows($result); // notice the Result Resource
here //
} else {
echo mysql_error();
// die();
}
Best Regards,

Apr 4 '06 #5
ppl, tnx very much on your anwsers.
I have dealed with this problem and solved it.
I have added this error checking, buth the real error was tiping mistake.
I have named mysql table "gred", and neaded "grad". and then mysql sead
"mysql_num_rows(): supplied argument is not a valid MySQL result
resource "

tnx again
Dejan
<we*****@gmail.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
Write your code like this:

$query = "....";
$result = mysql_query($query);
if($result) {
$num_rows = mysql_num_rows($result); // notice the Result Resource
here //
} else {
echo mysql_error();
// die();
}
Best Regards,

Apr 4 '06 #6
Dejan wrote:

Hi

Sorry for my terreble english.

On my local (win) comp i have apache+mysql+php 4.05
I'm counting rows using mysql_num_rows function, and everything works fine.
When i upload php file on server it says:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /home/optikara/public_html/crosun/izn/insert_form.php on line 80
Server runs php 5.0.5

Code is: [...] On my local comp this works. Plz any solution, in plain simple code:)))
tnx in advance.
Dejan


If it works at home then most likely the database connect code fails to
connect on the server.

Check the user and password parameters in your database connect code and
make sure they are correct on the server.

Bye!
Apr 4 '06 #7
First, you need to make your life a little easier by seperating out the
sql query:

$sql = "SELECT *
FROM my_table";

Assuming $db is a successful mysql_connect call...

$result = mysql_query($sql, $db) or die ("<p>$sql</p>" .
mysql_error());

If the query is bad, the script wont try to go any further

Apr 4 '06 #8

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

Similar topics

4
by: David Nikel | last post by:
I am attempting to create a login script. The following snippet of code: $query = "select * from auth where username='$username' and password=password('$password')"; $result =...
1
by: Hebron Mak | last post by:
Has anyone ran into problems where mysql_num_rows() return 0 when I know the result set contains a certain number of rows? My code looks something like this: MYSQL_RES *result; int numRows =...
3
by: petemaxi | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\tockholes\includes\menu.inc.php on line 9 <div class="left"> <div class="menu">...
1
by: google | last post by:
MySQL Server is version 4.1.7 (I know I should upgrade, and I will if that is the problem but it has been working fine for 1.5 years now and only recently has started to have this problem). Server...
1
by: d3vkit | last post by:
Alright I can not figure this one out, so I'm guessing it's some simple typo and some extra eyes will help me spot it. Here's the query (already connected to DB everything works in that respect):...
4
by: Ryanlawrence1 | last post by:
Heya, I get these 2 errors: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 20 You have not entered all the...
3
by: Sandman | last post by:
Hi, So I read the manual where it says to use mysql_affected_rows() for everything except SELECT and SHOW, and use mysql_num_rows() for those two, which actually return a result. However, I...
4
by: seigaku | last post by:
Hi everyone, I've recently begun learning PHP and it looks like I took on too much so soon. I'm attempting to fix a php script that detects whether or not a person is Eligible to join a...
2
by: macdalor | last post by:
Hi! I'm completely new to all dev and trying to put a website together using MySQLI and PHP; was running fine until I try to gather the DB content with the following script: <?...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
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
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.