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; Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 18, 2011 Share Posted March 18, 2011 One = in the query as well. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 18, 2011 Share Posted March 18, 2011 Oops, didn't see that. Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.