spangle1187 Posted March 18, 2011 Share Posted March 18, 2011 I am trying to pass in a $string variable into my query like so but it is returning a warning: $string = "clientName == '$input'"; $input = "Sam"; $table_id = 'booking'; $query ="SELECT * FROM booking WHERE. '$string' "; $test = mysql_query($query); echo $test; Link to comment https://forums.phpfreaks.com/topic/231010-passing-string-variable-into-mysql-query/ Share on other sites More sharing options...
Pikachu2000 Posted March 18, 2011 Share Posted March 18, 2011 Echo your $query variable and see what the query string looks like. Link to comment https://forums.phpfreaks.com/topic/231010-passing-string-variable-into-mysql-query/#findComment-1189171 Share on other sites More sharing options...
spangle1187 Posted March 18, 2011 Author Share Posted March 18, 2011 I have echoed the $query string and I was missing data so have reassembled the order: $input = "Sam"; $string = "clientName == '$input'"; $table_id = 'booking'; $query ="SELECT * FROM booking WHERE. '$string' "; $test = mysql_query($query); echo $query; and this is now showing the following for the $query string: SELECT * FROM booking WHERE. 'clientName == 'Sam'' which is correct but I still have a warning associated with $test = mysql_query($query); so this is where I will look now Link to comment https://forums.phpfreaks.com/topic/231010-passing-string-variable-into-mysql-query/#findComment-1189177 Share on other sites More sharing options...
kenrbnsn Posted March 18, 2011 Share Posted March 18, 2011 A query that looks like SELECT * FROM booking WHERE. 'clientName == 'Sam'' is not correct. Notice the "." after the WHERE and the single quote before the column name clientName and the extra single quote at the end. It should look like: SELECT * FROM booking WHERE clientName == 'Sam' You code to create the query is wrong. It should be <?php $input = "Sam"; $string = "clientName == '$input'"; $table_id = 'booking'; $query ="SELECT * FROM booking WHERE $string"; $test = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); ?> I added the "or die" clause for debugging purposes. Ken Link to comment https://forums.phpfreaks.com/topic/231010-passing-string-variable-into-mysql-query/#findComment-1189180 Share on other sites More sharing options...
PFMaBiSmAd Posted March 18, 2011 Share Posted March 18, 2011 One = in the query as well. Link to comment https://forums.phpfreaks.com/topic/231010-passing-string-variable-into-mysql-query/#findComment-1189181 Share on other sites More sharing options...
kenrbnsn Posted March 18, 2011 Share Posted March 18, 2011 Oops, didn't see that. Ken Link to comment https://forums.phpfreaks.com/topic/231010-passing-string-variable-into-mysql-query/#findComment-1189193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.