Jump to content

php mysql special characters


gjwolf

Recommended Posts

I'm having a problem trying to get my sql query to exectute correctly with Php
I 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 php
it doesn't work no matter what I try.  I know its tricky because of my field name has the backspace in it
and using special characters and I tried.. any help appreciated on what xxxxx should be would be very helpful.

here is the query that works





SELECT * FROM `bw` WHERE int_name like ('sfd-br01-tps-Serial0\/%:0\(%')

which returns what I want

sfd-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 in
my array.  No matter what I try I cannot get it to work any help appreciated.  Here is my
loop 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 array
foreach ($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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.