|
|||
|
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 |
|
|
||||
|
||||
|
|
|
|||
|
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 <webramz@gmail.com> wrote in message news:1144140487.542634.17920@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, > |
|
|||
|
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. jstucklex@attglobal.net ================== |
|
|||
|
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. ![]() |
|
|||
|
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. jstucklex@attglobal.net ================== |
|
|||
|
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! |
|
|||
|
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 |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|