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
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?

Link to comment
Share on other sites

<?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!';
   }

Link to comment
Share on other sites

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!';
}

 

 

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.