1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need sql Help

Discussion in 'PHP & Perl' started by zozor, Apr 4, 2009.

  1. zozor

    zozor Junior Member

    Joined:
    Dec 24, 2008
    Messages:
    113
    Likes Received:
    70
    Heres my code :
    PHP:
    <?php
    include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/simplepie.inc' 
    $feed = new SimplePie('http://www.yuddy.com/rss/celebritynews_rss.php'); // Rss feed
    $id=-1;

    foreach (
    $feed->get_items(05) as $item):
    $title=$item->get_title();
    $content=$item->get_description();
    $id=$id+1;
    echo 
    $id;
    echo 
    $title;
    echo 
    $content;
    mysql_connect("localhost:3307""dadboss_splog""computer");
    mysql_select_db("dadboss_splog");
    echo 
    "Connected to db";
    // On ajoute une entrée avec mysql_query
    mysql_query("INSERT INTO posts VALUES $id$title$content");
    mysql_close();
    echo 
    "Added into db";
    endforeach; 
    ?>
    Everything works well the content is well scraped and I get no sql errors but when I check In my database theres nothing in!
     
  2. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    try this:
    PHP:
    <?php

    include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/simplepie.inc' 

    $feed = new SimplePie('http://www.yuddy.com/rss/celebritynews_rss.php'); // Rss feed

    $id=-1;



    foreach (
    $feed->get_items(05) as $item):

    $title=$item->get_title();

    $content=$item->get_description();

    $id=$id+1;

    echo 
    $id;

    echo 
    $title;

    echo 
    $content;

    mysql_connect("localhost:3307""dadboss_splog""computer")or die(mysql_error());

    mysql_select_db("dadboss_splog")or die(mysql_error());

    echo 
    "Connected to db";

    // On ajoute une entrée avec mysql_query

    mysql_query("INSERT INTO posts VALUES ('$id', '$title', '$content')")or die(mysql_error());

    mysql_close();

    echo 
    "Added into db";

    endforeach; 
    ?>