mysql_real_escape_string stoping from reading from database

how can i allow sql query to not ignore space
Hi i the above scripts which picks up the data from the database now my problem is with this row [film_client_office ] because on this row the name has space example [EAST MIDLANDS] now when the sql query tries to match the field seems to not be able to retrive all the [film_client_office]row bacause it removes the space and instead it tries to match [EASTMIDLANDS] which doesnt match how can i get it so it pick up exacly what it is even with the space.
I have been reading about (mysql_real_escape_string) which i think that removes any space or funny characters but i tried to remove from my script but still doesnt pick it up the names with space here how the code looks like
and here is one of my url looks on the computer chrome. even thou on the database it looks like the name is EAST MIDLANDS but on chrome
http://500.401.22.45:23/onfilm/streaming/home/BELLWAY/EAST%20MIDLANDS/hofbell30468.mp4

if(!$sortby) { $sortby="lh"; }
	$client = mysql_real_escape_string($client);
	$office = mysql_real_escape_string($office);
	$sortby = mysql_real_escape_string($sortby);
	if($office=="All"){
	switch ($sortby) {
	case lh:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_status = 'on') ORDER BY film_location_price ASC";
	break;
	case hl:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_status = 'on') ORDER BY film_location_price DESC";
	break;
	default:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_status = 'on') ORDER BY film_location_price ASC";
	}
	}
	else{
	switch ($sortby) {
	case lh:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_client_office = '$office') AND (film_status = 'on') ORDER BY film_location_price ASC";
							break;
							case hl:
    $queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_client_office = '$office') AND (film_status = 'on') ORDER BY film_location_price DESC";
							break;
							default:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_client_office = '$office') AND (film_status = 'on') ORDER BY film_location_price ASC";
							}
							}

this i i call the url

$videourl ="http://500.401.22.45:23/onfilm/streaming/home/".$client."/".$row[film_client_office]."/".$row[film_filename].".mp4";

ok i think the problem doesnt seem to be on that line but on this line that i think removes the space or something can someone help
I think the problems seems to be on this part of the script which i dont quite understand which i think on this part it removes the space or something
because on the database i have one of the row has [EAST MIDLANDS] which on the url shows /home/BELLWAY/EAST MIDLANDS/hofbell30468.mp4 now this[EAST MIDLANDS] meamnt to match a folder with same name on my server but it doesnt match but if i had a name without space it match the folder on my server. so i am thinking is somewhere here that is either removing the sapces or something because it just doesnt pick ur with name that has space can someone help how do i get it so it match with or without space.


extract($_REQUEST,EXTR_SKIP);					    
function url_exists($url){						       
 $url = str_replace("http://", "", $url);						       
  if (strstr($url, "/"))
   {
	 $url = explode("/", $url, 2);						           
      $url[1] = "/".$url[1];						        
   }
    else
   {						           
	 $url = array($url, "/");
   }
     $fh = fsockopen($url[0], 80);
	    if ($fh)
   {
	 fputs($fh,"HEAD ".$url[1]." HTTP/1.1\
Host:".$url[0]."\
\
");
	    if (fread($fh, 22) == "HTTP/1.1 404 Not Found")
		 {
		   return FALSE;
		 }
		   else
		 {
		    return TRUE;
	     }
		 }
		  else
		 {
		   return FALSE;
		 }
		 }
?>

this the whole script

<link href="../css/www/eaofweb_clients.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/3.css" rel="stylesheet" type="text/css" media="all">
<link href="../css/www/template.css" rel="stylesheet" type="text/css" media="all" />
<link href="../css/www/eaofro_clients.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />				
<div align="center">
 
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="black" height="2">		<tr height="1">			<td width="100%" height="2"></td>		</tr>	</table>	
<?php	

extract($_REQUEST,EXTR_SKIP);					    
function url_exists($url){						       
 $url = str_replace("http://", "", $url);						       
  if (strstr($url, "/"))
   {
	 $url = explode("/", $url, 2);						           
      $url[1] = "/".$url[1];						        
   }
    else
   {						           
	 $url = array($url, "/");
   }
     $fh = fsockopen($url[0], 80);
	    if ($fh)
   {
	 fputs($fh,"HEAD ".$url[1]." HTTP/1.1\
Host:".$url[0]."\
\
");
	    if (fread($fh, 22) == "HTTP/1.1 404 Not Found")
		 {
		   return FALSE;
		 }
		   else
		 {
		    return TRUE;
	     }
		 }
		  else
		 {
		   return FALSE;
		 }
		 }
?>

<?php 
	include("../includes/config.php");

	//connect to DB
	//connect to DB
$connectionproplst = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT.");
$dbproplst = @mysql_select_db($db_name, $connectionproplst) or die("Couldn't select DATABASE.");
	//$client=$_REQUEST['client'];	
$queryproplst = "SELECT * FROM films WHERE (film_client = '$client')";

$qry_resultproplst = mysql_query($queryproplst) or die(mysql_error());

$row = mysql_fetch_array($qry_resultproplst) or die(mysql_error());
?>
<img src="../images_agents_logos/<?php echo $row[film_client]; ?>.gif" alt="" height="80" width="320" border="0" />	

<?php echo '<br />'; ?>
<?php						//get the DB connection variables
	include("../includes/config.php");
	//connect to DB
	$connectionproplst = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT.");
	$dbproplst = @mysql_select_db($db_name, $connectionproplst) or die("Couldn't select DATABASE.");
	//$client=$_REQUEST['client'];
	if(!$client){$client="HOUSESETC";}
	$office="All";
	$sortby="hl";
	if(!$sortby) { $sortby="lh"; }
	$client = mysql_real_escape_string($client);
	$office = mysql_real_escape_string($office);
	$sortby = mysql_real_escape_string($sortby);
	if($office=="All"){
	switch ($sortby) {
	case lh:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_status = 'on') ORDER BY film_location_price ASC";
	break;
	case hl:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_status = 'on') ORDER BY film_location_price DESC";
	break;
	default:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_status = 'on') ORDER BY film_location_price ASC";
	}
	}
	else{
	switch ($sortby) {
	case lh:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_client_office = '$office') AND (film_status = 'on') ORDER BY film_location_price ASC";
							break;
							case hl:
    $queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_client_office = '$office') AND (film_status = 'on') ORDER BY film_location_price DESC";
							break;
							default:
	$queryproplst = "SELECT * FROM films WHERE (film_client = '$client') AND (film_client_office = '$office') AND (film_status = 'on') ORDER BY film_location_price ASC";
							}
							}
							
//echo "<br/>".$queryproplst;
$qry_resultproplst = mysql_query($queryproplst) or die(mysql_error());
    while($row = mysql_fetch_array($qry_resultproplst)){
        if ($mybgcount==1)
		 {
           $mybgcolor="E8E8E8";
           $mybgcount=0;
         }
		  else
		 {
          $mybgcolor="FFC3FF";
          $mybgcount=1;
         }
?>
<?php
$bgimgurl ="http://www.onfilm.biz/streaming/home/".$client."/".$row[film_client_office]."/".$row[film_filename].".jpg";
$videourl ="http://000.000.00.00:00/onfilm/streaming/home/".$client."/".$row[film_client_office]."/".$row[film_filename].".mp4";
//check if file exisits
if (url_exists($videourl)) {
// if it does exist then...
// don't change $videourl
$fgimgurl	="images/thumb_click_image_on.png";
$videourl		=$videourl;
}
else
{
//else set $videourl to coming_soon.mp4 at root level
$fgimgurl	="images/thumb_click_image_off.png";
$videourl		="";
//$videourl		="http://000.000.00.00:00/onfilm/streaming/home/coming_soon.mp4";
}
?>	

<table style="padding-top:20px;" width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="<?php if(!$mybgcol || $mybgcol=0){ echo "white"; $mybgcol=1; } else{ echo "#E9E9E9"; $mybgcol=0; }?>">		   <tr>
      <td align="center">
<table align="left" width="329" border="0" cellspacing="0" cellpadding="0">
   <tr>
      <td align="left" valign="top" width="160">
<table width="160" border="0" cellspacing="0" cellpadding="0" background="../search_phpthumb/phpThumb.php?src=<?php echo $bgimgurl; ?>&w=160&h=90&iar=on" height="90">								   <tr height="56">
	  <td align="right" valign="bottom" width="152" height="56">
	    <?php if($videourl){echo "<a title='Play Video' href='$videourl'>";} ?>
        <img src="<?php echo $fgimgurl; ?>" alt="<?php echo $row[film_postcode]; ?>" name="photo" width="152" height="56" border="0" id="photo">
        <?php if($videourl){echo "</a>";} ?>
     </td>
     <td align="right" valign="bottom" width="8" height="56"></td>
  </tr>	
  <tr height="16">Address here
     <td valign="bottom" width="152" height="16" background="../tv/jrp/thumb_text_image.png"> <span style="text-align:left; color:white; font-size:10px;">Beds:<?php echo strtoupper($row[film_location_bedrooms]); ?></span><span class="hofwhite10" style="text-align:right;">
	 <?php echo strtoupper($row[film_location_town]); ?></span></td>
     <td align="right" valign="top" width="8" height="16" background="../tv/jrp/thumb_text_image.png"></td>
  </tr>
  <tr height="16">
 <td align="right" valign="top" width="152" height="16" background="../tv/jrp/thumb_text_image.png"><span class="hofwhite10">£ <?php if($row[film_location_price]==1){ echo "POA"; } else
  { 
  echo number_format($row[film_location_price]); } ?></span></td>
    <td align="right" valign="top" width="8" height="16" background="../tv/jrp/thumb_text_image.png"></td>
 </tr>
</table>
	</td>
    <td align="left" valign="top" width="8"></td>
    <td align="left" valign="top" width="161">
<table width="153" height="23" border="0" cellpadding="0" cellspacing="0">
  <tr height="4">
  	<td width="162" height="4" align="left" valign="top"></td>
  </tr>
  
  <tr>
  	<td style="font-size:9px;" align="left">
      <?php	echo substr($row[film_location_description],0,250);	?>...	</span>	<a class="inlinelinklocal" href='<?php echo $row[film_client_detailsURL]; ?>'>more...</a>

	   </td>
    </tr>
  	
   
</table>
      </td>
    </tr>
</table>
   	  </td>
    </tr>
</table>
<table class="purple" width="100%" height="1" border="0" cellpadding="0" cellspacing="0">
	<tr height="1">
    	<td width="100%" height="1"></td>
        	</tr>
</table>	<?php// echo url_exists($videourl);?>
 <?php } ?>
  <?php	mysql_close($connectionproplst);?>
</div>

Ok i think theres nothing wrong with my code the only problem i think seems to be because i am running the script on safari so safari replaces space with EAST%20MIDLANDS percetage sign and a 20 because of that the ur doesnt east midland doesnt match the exact folder how can i make so that script ignores that on safari so that it matches my folder which is[east midlands] and not [east%20midlands] i think that will solve my problem open to any suggestion

THIS is why spaces in anything you’re passing as a index is usually a REALLY BAD IDEA… though again using the old/outdated mysql_ functions are equally biting out on that with your having to run a sanitize.

I would suggest running
PHP: urldecode - Manual

before running it through the sanitizer – as the sanitizer is probably escaping the % signs.

Also, you’re not outputting sortby to the query, so there’s no need to sanitize it… and I’d be checking for isset, not “not false” – though I’d have to see where most of these variables are being set in your code to say for sure. I get the feeling that the code in your first post is 1.5k of code doing half a K’s job given all the ‘lather, rinse, repeat’ you’ve got in there.

Yeah, that’s WAY too much code for something so simple.


	if (!isset($sortby)) $sortby='lh';

	$client = mysql_real_escape_string(urldecode($client));
	$office = mysql_real_escape_string(urldecode($office));

	$queryproplst="
		SELECT * FROM films
		WHERE (film_client='$client') AND (film_status='on')".(
			$office=='All' ? '' : " AND (film_client_office='$office')"
		),"
		ORDER BY film_location_price ".($sortby=='hl' ? 'DESC' : 'ASC');

396 bytes to your 1.5k.

really though, URLDecode is what you really need to fix it.

Looking at your second post – what is with that screwball nonsensical indentation style? I’m shocked you’re able to close everything properly…

Big tip though, you’re REALLY overthinking a lot of your code. That URL_exists function for example:


function url_exists($url) {
	$parsed=parse_url($url);
	if ($fh=fsockopen($url[0],80)) { 
		fputs($fh,"HEAD $parsed[path] HTTP/1.1\
Host:$parsed[host]\
\
");
		return ((fgets($fh)!='HTTP/1.1 404 Not Found'));
	}
	return false;
}

Guess that goes hand in hand with all the opening and closing PHP for nothing you have in there… endless multiple CSS files being sent to “all” (which is VERY unlikely to be what’s actually desired for behavior, sure anyone on a handheld or trying to print it REALLY appreciates that)… I mean I’m seeing table for layout, I’m ASSUMING that’s LINK inside BODY (which is WRONG), single TD tables (which means what the devil is the table FOR?)

Gimme a few minutes, I’ll take a stab at cleaning up what you have… though it’s tough with all that outdated/oddball markup in there… it’s like a visit to 1997.

Hi thanks for the help so far. the code was done by a previous developer which i no longer am in contact with so i am trying to fix it myself i am just learning php so dont really want to change much as i am still a beginner.
i have read about the link urldecode link you have sent me but either is my thick head that cnt get around it or i am doing wrong i have change the following line with the urldecode but still no luck do i need to add something else or just that urldecode?

 if(!$sortby) { $sortby="lh"; }
	$client = mysql_real_escape_string(urldecode($client));
	$office = mysql_real_escape_string(urldecode($office));

one of my question is that the code works fine when it comes to pick up an image from that folder for example
http://www.mysite.com/folder1/folder2/folder3/EAST%20MIDLANDS/hofbell30468.jpg
it manages to pick up the image fine but when it tries to do the same for the video it doesnt pick up because of the %20 replacing space why
http://www.mysite.com/folder1/folder2/folder3/EAST%20MIDLANDS/hofbell30468.mp4
as the only difference is just the file extension from jpg to mp4

I’d have to go in and see what values are being returned – maybe (though unlikely) the EXTRACT that turns $_REQUEST into local vars (one of the DUMBEST most insecure memory wasting things that can be done in code) is messing with it somehow.

Seriously this:


extract($_REQUEST,EXTR_SKIP);

Would have me hunting down that original coder for a pimp-slap… The HTML part if it was written less than six to eight years ago, would have me hunting for a baseball bat.

Even just simple stuff like:


 if(!$sortby) { $sortby="lh"; }

has to be filling up the log file with endless silent errors every time it runs if sortby doesn’t exist. You cannot “not” a non-existant variable, that’s why the isset functon exists.

There’s so much invalid code and outdated processes in there, I’d advise throwing it out and starting over from scratch regardless of your skill level, because that code is SO disastrously bad as someone starting with PHP it’s just going to teach you the wrong way of doing things.

Though also, this is why you rarely if ever see anyone use spaces in URL’s, directory names, or filenames on the web. Switch to an underscore (east_midlands), or a hypen (east-midlands), or use camelBacks (eastMidlands)… these techniques exist for a reason.