SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to check whether the URL exists in the database

    I am tried, but I get mistake.
    Although the site does not exist in the database I get the following error .

    Sorry, but this URL already exists in our database

    PHP Code:

    <?php

    $server 
    "localhost";
    $user "root";    
    $password "";      
    $mysqlbase "test";     
    $conn=mysql_connect($server,$user,$password) or die(erreurServeurMySQL());
    mysql_select_db($mysqlbase,$conn) or die('Error '.mysql_error());

    $feed_url "*****url rss feed*********";

    $curl curl_init();

    curl_setopt($curlCURLOPT_URL,"$feed_url");
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT0);

    $xmlTwitter curl_exec($curl);

    curl_close($curl);

    $xml simplexml_load_string($xmlTwitter);

    foreach (
    $xml->channel->item as $oItem)
    {
       

    $sql "SELECT * FROM rss_news WHERE link='$link'";
    $prikazi mysql_query($sql) or die('Error !'.$sql.'<br>'.mysql_error()); 
        
    $res mysql_num_rows($prikazi);

    if(
    $res!=0)  / / Url already existsit displays an error message
    {
    echo 
    '<font color="red">Sorry, but this URL already exists in our database.</font><br>';
    }
    else  / / 
    The URL does not existinsert the information in the form of table
    {   

     
    $sql sprintf("INSERT INTO rss_news (`id`,`title`,`link`,`description`,`timestamp`)VALUES('','%s','%s','%s',%

    s)"
    ,
            
    mysql_escape_string($oItem->title),
            
    mysql_escape_string($oItem->link),
            
    mysql_escape_string($oItem->description),
            
    time()
        );
        
    mysql_query($sql);
    echo 
    'Informacije upisane u bazu<br>';
    }

    ?>

    Data are not recorded in the database.

    Hope that if there is the same site do not enter the base.
    If the URL does not exist, enter the base.

    Please help

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. Why are you using CURL? What's wrong with:

    PHP Code:
    $xml simplexml_load_file('http://example.com'); 
    2. Looking at your SQL statement, you're using a variable that does not exist.

    PHP Code:
    $sql "SELECT * FROM rss_news WHERE link='$link'"// $link is undefined, you probably mean $oItem->link? 
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Indeed. Judging by it's position within the loop, it appears as though it should probably read:
    Code PHP:
    $sql = "SELECT * FROM rss_news WHERE link='{$oItem->link}'";

    Of course, it would probably be better as:
    Code PHP:
    $sql = sprintf("SELECT * FROM rss_news WHERE link='%s'", 
                mysql_real_escape_string($oItem->link));

    Edit: Since that is what is used later in the insert. Haven't used SimpleXML in forever.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •