sKunKbad Posted March 22, 2009 Share Posted March 22, 2009 I'm having trouble with a mysql query. Specifically, I am looping through some queries, and I have a variable variable inside the query which I'm sure is causing the problem. Actually there are two variable variables. Right now the error is: Parse error: syntax error, unexpected '{', expecting ']' in C:\wamp\www\loginTest\status.inc.php on line 200 Here is the query: mysqli_query($db , "UPDATE `{$type}s` SET login_hold = 0 WHERE " . $type . "_id = '{$row[{"$type" . "_id"}]}' LIMIT 1"); I know I'd eventually get it, but some help is appreciated. Link to comment https://forums.phpfreaks.com/topic/150632-solved-variable-variable-inside-mysqli_query/ Share on other sites More sharing options...
.josh Posted March 22, 2009 Share Posted March 22, 2009 Nothin' else, could just separate it: $t = "{$type}_id"; mysqli_query($db , "UPDATE {$type}s SET login_hold = 0 WHERE $t = '{$row[$t]}' LIMIT 1"); Link to comment https://forums.phpfreaks.com/topic/150632-solved-variable-variable-inside-mysqli_query/#findComment-791280 Share on other sites More sharing options...
sKunKbad Posted March 22, 2009 Author Share Posted March 22, 2009 That's what I had to do. It's weird that I could do something like this: <?php $type= "user"; $row['user_id'] = 13874; $query = "UPDATE `{$type}s` SET login_hold = 0 WHERE " . $type . "_id = '" . $row[$type . _id] . "' LIMIT 1"; echo $query; ?> but when the query is actually inserted into mysqli_query, it doesn't work anymore. Link to comment https://forums.phpfreaks.com/topic/150632-solved-variable-variable-inside-mysqli_query/#findComment-791305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.