gjwolf Posted July 7, 2006 Share Posted July 7, 2006 I'm having a problem trying to get my sql query to exectute correctly with PhpI can show you what works in phpadmin and what I want to do to make it clearer to articulate.The following query works good for me in phpmyadmin but when I try to substitue the serach string in phpit doesn't work no matter what I try. I know its tricky because of my field name has the backspace in itand using special characters and I tried.. any help appreciated on what xxxxx should be would be very helpful. here is the query that worksSELECT * FROM `bw` WHERE int_name like ('sfd-br01-tps-Serial0\/%:0\(%')which returns what I wantsfd-br01-tps-Serial0/0:0(In) sfd-br01-tps-Serial0/0:0(Out) sfd-br01-tps-Serial0/1:0(In) sfd-br01-tps-Serial0/1:0(Out) sfd-br01-tps-Serial0/2:0(In) sfd-br01-tps-Serial0/2:0(Out) the problem I'm having is on how to put this in php and make it work correctly as a variable inmy array. No matter what I try I cannot get it to work any help appreciated. Here is myloop and code I put xxxx for the variable as whatever I have tried doesn't work.$hosts = array('xxxxx');// Loop through each element in the arrayforeach ($hosts as $host_str){// Request the text of all records that meet this criteria$query = "SELECT * FROM cpu WHERE name LIKE '$host_str' order by name"; $result = mysql_query($query);if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $result; die($message);} g Quote Link to comment Share on other sites More sharing options...
fenway Posted July 8, 2006 Share Posted July 8, 2006 You probably just need to SQL-escape your string. Quote Link to comment Share on other sites More sharing options...
gjwolf Posted July 8, 2006 Author Share Posted July 8, 2006 Hi fenway I'm searching for what you said but how would I do that ?G Quote Link to comment Share on other sites More sharing options...
fenway Posted July 8, 2006 Share Posted July 8, 2006 PHP has a few built-in functions for this; I've always done it myself. Quote Link to comment Share on other sites More sharing options...
gjwolf Posted July 9, 2006 Author Share Posted July 9, 2006 Fenway, can you show me what you mean?thanks, Quote Link to comment Share on other sites More sharing options...
fenway Posted July 10, 2006 Share Posted July 10, 2006 Check out the addslashes() PHP function. Quote Link to comment Share on other sites More sharing options...
gjwolf Posted July 10, 2006 Author Share Posted July 10, 2006 Fenway, I really appreciate you giving me the tips.. it workedthanks a bunch!G 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.