| Author |
Message |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2963 Location: Earth
|
Posted: Thu Feb 28, 2008 5:34 am Post subject: implode error - PHP |
|
|
| 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
|
Posted: Thu Feb 28, 2008 5:57 am Post subject: |
|
|
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
|
Posted: Thu Feb 28, 2008 6:56 am Post subject: |
|
|
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
|
Posted: Thu Feb 28, 2008 7:53 pm Post subject: |
|
|
| 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 |
|
| |
|
|
|