Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts

    sql wont insert my varible values? not sure why

    hi all,

    i am having some trouble with entering my data into a database table

    i have loaded a rss feed and have managed to pull out the specific elements from it and i have echo'd them out to check that they are correct which they are, but for some reason it doesnt like my varibles

    here is my code
    PHP Code:
     $xml=("http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&TD_PARAM=http://clkuk.tradedoubler.com/click?p=23708&a=1515427&url=");


    $xmlDoc = new DOMDocument();
    $xmlDoc->load($xml);

    for (
    $i 0$i 10$i++) {
    //get elements from "<channel>"
    $channel=$xmlDoc->getElementsByTagName('entry')->item($i);
    $channel_title $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
    $channel_image str_replace("30x30-50","100x100-75",$channel->getElementsByTagName('image')->item(0)->childNodes->item(0)->nodeValue);
    $channel_link $channel->getElementsByTagName('id')->item(0)->childNodes->item(0)->nodeValue;
    $channel_album $channel->getElementsByTagName('name')->item(0)->childNodes->item(0)->nodeValue;
    $channel_artist $channel->getElementsByTagName('artist')->item(0)->childNodes->item(0)->nodeValue;
    $channel_cost $channel->getElementsByTagName('price')->item(0)->childNodes->item(0)->nodeValue;

    $sql "INSERT INTO product_database (pID,store,productTitle) VALUES ($i,'itunes',$channel_title)";
    $query mysql_query($sql);

    //output elements from "<channel>"

    echo ("<a href='$channel_link'>".$channel_title."</a>");
    echo(
    "<br />");
    echo 
    $channel_album;
    echo(
    "<br />");
    echo 
    $channel_artist;
    echo(
    "<br />");
    echo 
    $channel_cost;
    echo(
    "<br />");
    echo (
    "<img src='$channel_image'>");
    echo(
    "<br />");
    }
    ?> 
    it adds the $i and the storeName but nothing else?

    any ideas where im going wrong, please

    thanks
    Luke

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    ok i have solved it turns out you need to add '' around the varible name oops

    cheers

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    ok another problem,

    i am trying to get my search function to search this table for all productTitles which are like $test

    $test is the value that the user inputted into my search bar,

    before i was using preg_match but not in my sql code can this be done in sql?

    this is the code i was using
    PHP Code:
    if (preg_match("/\b$test\b/i",productTitle)){
                        list(
    $width$height) = getimagesize($item->uri->mImage);
                           
                                echo
    "data"
    but i tried to add preg_match into my sql code and it didnt like the /\'s

    here is my current code
    PHP Code:
    $sql "SELECT *
            FROM product_database
            WHERE productTitle LIKE '$test'"
    ;

    $query mysql_query($sql);
    $row mysql_fetch_array($query);
    $num_rows mysql_num_rows($query);
    $title $row['productTitle'];
    for (
    $i $num_rows$i 0$i++){                   
    echo 
    $title;

    if i change $test to poker i expect it to pull out poker face by lady gaga, but it doesnt even though its in the database. i have tried entering it directly into my sql engine but it still returns nothing?

    how do i get it to pull out info similar or includes the string value of $test

    cheers
    Luke


  •  

    Posting Permissions

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