LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-09-2007, 04:05 AM   #1
kits
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Rep: Reputation: 0
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 .
 
Old 01-09-2007, 04:19 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
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);
 
Old 01-09-2007, 04:21 AM   #3
kits
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Original Poster
Rep: Reputation: 0
i had tried but it died, too. Actually, your and my code is the same.

Last edited by kits; 01-09-2007 at 04:22 AM.
 
Old 01-09-2007, 04:23 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
What is the error message - mysql_error should show it, no?
 
Old 01-09-2007, 04:25 AM   #5
kits
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Original Poster
Rep: Reputation: 0
Nothing happened. But in my localserver, runs always correct with my code.
 
Old 01-09-2007, 04:31 AM   #6
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
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.
 
Old 01-09-2007, 04:35 AM   #7
kits
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Original Poster
Rep: Reputation: 0
But my server doesnot print error. So how to know what error? It runs correct!
 
Old 01-09-2007, 04:46 AM   #8
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
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.
 
Old 01-09-2007, 04:52 AM   #9
kits
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Original Poster
Rep: Reputation: 0
no in there error. i had checked. Correct everything. Using software to check is correct, too.
 
Old 01-09-2007, 05:12 AM   #10
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
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());
 
Old 01-10-2007, 03:55 AM   #11
kits
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Original Poster
Rep: Reputation: 0
thank for help, i think i had found problem. When solve, i wil post.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
anything wrong with this code? bytez Linux - Software 1 09-19-2006 04:52 AM
What is wrong with this C++ code? frankie_DJ Programming 5 10-01-2005 06:19 PM
What is wrong with this C code ? indian Programming 8 04-16-2005 04:42 AM
what ' s wrong in code ? phoenix_fei Programming 4 12-17-2004 12:32 PM
What is wrong with this code? qanopus Programming 4 03-12-2004 07:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration