Jump to content

[SOLVED] Problems using URLs in queries


hellonoko

Recommended Posts

My code below compares a link to a DB full of links.

If the link is already in the DB it display the appropriate response.

 

As it stands both links (fisrt two lines) are in the DB.

If test is used my code works fine. However when I use the real url I get no output. No errors. Is there something I need to be doing when I am handling URLS in and outside of my DB?

 

Any ideas?

 

//$last_cralwed_link = "this.bigstereo.net/wp-content/uploads/2009/03/tomorrow-wow-remix.mp3";
$last_crawled_link = "test";

$query = mysql_query("SELECT * FROM `primarylinks` WHERE `link` = '$last_crawled_link' LIMIT 1") or die(mysql_error());

$rows = mysql_num_rows($query) or die(mysql_error());
//
if ( $rows == 0)
	{
	echo ' no such link';
}
else
{
	echo ' link in DB!';
}

Link to comment
https://forums.phpfreaks.com/topic/150553-solved-problems-using-urls-in-queries/
Share on other sites

Well its crawling music blogs. The links will eventually be used to copy mp3s.

 

I worked through my code a little deeper and found that at this line:

 

echo $last_crawled_link = mysql_real_escape_string($last_crawled_link) or die(mysql_error());

 

The variable just goes away. That is mysql_real_escape_string turns it from a url into empty.

 

Any ideas?

<?php
//$last_cralwed_link = "this.bigstereo.net/wp-content/uploads/2009/03/tomorrow-wow-remix.mp3";
   $last_crawled_link = "test";
   
   $query = mysql_query("SELECT * FROM `primarylinks` WHERE `link` LIKE = '%$last_crawled_link%' LIMIT 1") or die(mysql_error());
   
   $rows = mysql_num_rows($query) or die(mysql_error());
   //
   if ( $rows == 0)
    {
      echo ' no such link';
   }
   else
   {
      echo ' link in DB!';
   }

I see but don't I want to be a bit more exact since urls could be very similar but different?

 

Still not sure what is happening as the below code returns neither in db or not in db.

 

//echo $last_cralwed_link = "this.bigstereo.net/wp-content/uploads/2009/03/tomorrow-wow-remix.mp3";
echo $last_crawled_link = "thisisnotinthedb";

$query = mysql_query("SELECT * FROM `primarylinks` WHERE `link` LIKE '%$last_crawled_link%' LIMIT 1") or die(mysql_error());

$rows = mysql_num_rows($query) or die(mysql_error());
//
if ( $rows == 0)
	{
	echo ' no such link';
}
else
{
	echo ' link in DB!';
}

 

 

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.