Jump to content


Photo

php mysql special characters


  • Please log in to reply
6 replies to this topic

#1 gjwolf

gjwolf
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 07 July 2006 - 06:50 PM

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

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 08 July 2006 - 12:39 AM

You probably just need to SQL-escape your string.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 gjwolf

gjwolf
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 08 July 2006 - 06:40 AM

Hi fenway I'm searching for what you said but how would I do that ?

G

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 08 July 2006 - 04:16 PM

PHP has a few built-in functions for this; I've always done it myself.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 gjwolf

gjwolf
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 09 July 2006 - 12:52 PM

Fenway,  can you show me what you mean?



thanks,

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 July 2006 - 12:59 AM

Check out the addslashes() PHP function.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 gjwolf

gjwolf
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 10 July 2006 - 12:08 PM

Fenway, I really appreciate you giving me the tips.. it worked
thanks a bunch!

G




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users