LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What wrong in this code (https://www.linuxquestions.org/questions/programming-9/what-wrong-in-this-code-517628/)

kits 01-09-2007 04:05 AM

What wrong in this code
 
dear friends
i have this code:
Quote:

$cnt = mysql_num_rows(mysql_query("select mahang from shop_hang where macatalog='$macatalog'")) or die (mysql_error());
when run in local server, it runs correct, but when upload to real server, it died. Please show me, what wrong in this code. thank .

Guttorm 01-09-2007 04:19 AM

Hi

If there are no rows returned, it will die.

Kind of like this
Code:

$cnt = 0 or die(mysql_error());
(will die)

Try instead:
Code:

$result = mysql_query("select mahang from shop_hang where macatalog='$macatalog'") or die (mysql_error());
$cnt = mysql_num_rows($result);


kits 01-09-2007 04:21 AM

i had tried but it died, too. Actually, your and my code is the same.

Guttorm 01-09-2007 04:23 AM

What is the error message - mysql_error should show it, no?

kits 01-09-2007 04:25 AM

Nothing happened. But in my localserver, runs always correct with my code.

Guttorm 01-09-2007 04:31 AM

Hmm... I don't know. Production servers are often set up to not show any error messages, but only log them. Check the error logs if you have access to them. Otherwise, perhaps try:

error_reporting(E_ALL ^ E_NOTICE);

or maybe:

error_reporting(E_ALL);

Last one usually gives lots of warnings.

kits 01-09-2007 04:35 AM

But my server doesnot print error. So how to know what error? It runs correct!

Guttorm 01-09-2007 04:46 AM

Could be a few things, like:
- The table/column is missing in the database on the production server
- No php-mysql installed
- register globals are turned off, so $macatalog is empty
- the error is elsewhere?

Did you try the error_reporting in the beginning of the script? It should give you a clue what the problem is.

kits 01-09-2007 04:52 AM

no in there error. i had checked. Correct everything. Using software to check is correct, too.

Guttorm 01-09-2007 05:12 AM

You sure it's that die that gets executed?

Maybe change it to something like:
Code:

$result = mysql_query("select mahang from shop_hang where macatalog='$macatalog'")
or die ("Error in line ".__LINE__." File: ".__FILE__.": ".mysql_error());


kits 01-10-2007 03:55 AM

thank for help, i think i had found problem. When solve, i wil post.


All times are GMT -5. The time now is 01:33 AM.