Jump to content

problem with str_replace


ravensshade

Recommended Posts

hi i'm getting the following error SELECT mwa.Name,hw.Value FROM HardwareData AS hw FULL JOIN MachinesWithAgents AS mwa on hw.MachineID=mwa.MachineID WHERE mwa.Name LIKE EU\\MOON

 

using this code:

// removed login info for security
MSSQL_CONNECT("") or DIE("DATABASE FAILED TO
RESPOND."); 
mssql_select_db("SSISurvey") or DIE("Table unavailable");

$Name = str_replace ( "\\" ,"\", $_GET['name']);

$query = "SELECT mwa.Name,hw.Value FROM HardwareData AS hw FULL JOIN MachinesWithAgents AS mwa on hw.MachineID=mwa.MachineID WHERE mwa.Name LIKE $Name";

however str replace doesn't seem to do anything..

Link to comment
https://forums.phpfreaks.com/topic/191486-problem-with-str_replace/
Share on other sites

The string replace as you have it, will do exactly nothing

 

the backslash is an escape character to needs to be escaped itself so the best you are asking there is to replace a backslash with a backslash

 

Not 100% sure on this one but this might work better

$Name = str_replace ( "\\\\" ,'\', $_GET['name']);

 

The string replace as you have it, will do exactly nothing

 

the backslash is an escape character to needs to be escaped itself so the best you are asking there is to replace a backslash with a backslash

 

Not 100% sure on this one but this might work better

$Name = str_replace ( "\\\\" ,'\', $_GET['name']);

well i do infact need a single backslash instead of 2

also your solution ends up in

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /nfs/atlas/web/sec/IS/surveytest/results.php on line 5

Personally.. I would fix the input, if you can, for the GET variable.. itll be a hell of alot cleaner than doing this...

In any case, this is how you need it.. as ugly as it is...

str_replace ( "\\\\" ,"\\", $_GET['name']);

yeah i changed the statment

str_replace ( "EU\\\\" ,"", $_GET['name']);

and let the query search for ('%$Name%')

alexjb: i noticed that aswell yes gonna fix that now knowhow to do that allready

 

thanks for the help

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.