Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

implode error - PHP

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2963
Location: Earth

PostPosted: Thu Feb 28, 2008 5:34 am    Post subject: implode error - PHP Reply with quote

Quote:
Warning: implode() [function.implode]: Bad arguments. in /usr/home/desbrina/public_html/mt/users/master.php on line 72
UPDATE user_inventory set status = 'mastered' WHERE ID IN()
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1


I get that error with this code
Code:
$sql = "UPDATE user_inventory set status = 'mastered' WHERE ID IN(".implode(', ', $ids).")";
$result = mysql_query($sql) or die($sql."<br />".mysql_error());

IDs are entered via
Code:
$ids = array();
         while($row = mysql_fetch_array($sql)) {
            $ids[] = $row['ID'];
         }


I'm a bit confused since it was working fine yesterday
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4627
Location: Down Under

PostPosted: Thu Feb 28, 2008 5:57 am    Post subject: Reply with quote

Umm... where to start!?

implode() is probably failing because $ids is not an array, BTW, that is a poor name for a variable, at least use $IDs. Although, from what I see, $ids is clearly being set, at least as an empty array. Are you sure $ids is in scope of the first snippet or that the second snippet is executed before the first?

mysql_fetch_array($sql) should probably have $result as the argument or whatever you use. Which would explain the empty $ids array and the SQL query that results.
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2963
Location: Earth

PostPosted: Thu Feb 28, 2008 6:56 am    Post subject: Reply with quote

if i print it after its set, so after
Code:
$ids = array();
         while($row = mysql_fetch_array($sql)) {
            $ids[] = $row['ID'];
         }
print_r($ids);

Then it shows the IDs fine

But if i print it after the first piece of code then its blank. I changed the variable to session and it works, so the variable seems to be getting lost when the page is reloaded
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4627
Location: Down Under

PostPosted: Thu Feb 28, 2008 7:53 pm    Post subject: Reply with quote

Judging by the levels of indentation of the second snippet, I take it that it was in a class or a function? If so, did you consider the possibility of an out of scope issue that I mentioned last post? That would explain why using session variables works.
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com