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 7 of 7
  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    MySQL SELECT Wont Run?!!?

    PHP Code:
    <?php
        $url 
    $_SERVER['REQUEST_URI'];
        
    $split preg_split('/\//'$url);
        
        
    mysql_connect("mysql.xxxxxxxxx.com""xxxxxxxxx""xxxxxxxxx");
        
    mysql_select_db("branchr");
        
        
    $user mysql_query("SELECT * FROM social_trees WHERE username = '$split[1]'");
        
    $branches mysql_query("SELECT * FROM network_branches WHERE user = '$split[1]'");
        
        
    $row mysql_fetch_array($user);
        
        
    $u $split[1];
    ?>


    <?php echo $row['username']; ?> >> 

    <?php
        
    while($row1 mysql_fetch_array($branches)) {
         
         
    $brnch $row1['id'];
         
    $url $row1['network_feed'];
        
    $net =  $row1['network'];
        
        
    $ch curl_init($url);
        
        
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
    curl_setopt($chCURLOPT_HEADER0);
        
        
    $data curl_exec($ch);
        
    curl_close($ch);
        
        
    $doc = new SimpleXmlElement($dataLIBXML_NOCDATA);
        function 
    parseRSS($xml$u$net$brnch)
    {
       
        
    $cnt count($xml->channel->item);
        for(
    $i=0$i<$cnt$i++)
        {
        
    $url     $xml->channel->item[$i]->link;
        
    $title     $xml->channel->item[$i]->title;
        
    $desc $xml->channel->item[$i]->description;
        
    $date $xml->channel->item[$i]->pubDate;
         
    // But this doesnt
         
    $isitthere mysql_query("SELECT * FROM `data` WHERE data.title = '$title' AND data.date = '$date' AND data.user = '$u'");
         
    $counter 0;
         
         while(
    $isrow mysql_fetch_array($isitthere)) {
             
    $counter ++;
         }
         
         if(
    $counter == '0') {
         
    // The code below runs!
        
    mysql_query("INSERT INTO data VALUES ( NULL, '$title', '$desc', '$date', '$u', '$net', '$brnch' )");
        
        }
        }
    }


        if(isset(
    $doc->channel))
        {
            
    parseRSS($doc$u$net$brnch);
        }
        

        }
    ?>
    See code comments for where it is, basically the bottom SQL executes but the top one doesn't. I get the following error:
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.zusa/christianowens/branchr.com/user.php on line 50

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    $user = mysql_query("SELECT * FROM social_trees WHERE username = '".$split[1]."' ");
    $branches = mysql_query("SELECT * FROM network_branches WHERE user = '".$split[1]."' ");

    $isitthere = mysql_query("SELECT * FROM `data` WHERE data.title = '".$title."' AND data.date = '".$date."' AND data.user = '".$u."'");


    try that
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Same errors,

    Here is the updated code with your suggestion:

    PHP Code:
    <?php
        $url 
    $_SERVER['REQUEST_URI'];
        
    $split preg_split('/\//'$url);
        
        
    mysql_connect("xxxxxxxxxxxxxxxxxx""xxxxxx""xxxxxx");
        
    mysql_select_db("branchr");
        
        
    $user mysql_query("SELECT * FROM social_trees WHERE username = '".$split[1]."' ");
    $branches mysql_query("SELECT * FROM network_branches WHERE user = '".$split[1]."' ");
        
        
    $row mysql_fetch_array($user);
        
        
    $u $split[1];
    ?>


    <?php echo $row['username']; ?> >> 

    <?php
        
    while($row1 mysql_fetch_array($branches)) {
         
         
    $brnch $row1['id'];
         
    $url $row1['network_feed'];
        
    $net =  $row1['network'];
        
        
    $ch curl_init($url);
        
        
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
    curl_setopt($chCURLOPT_HEADER0);
        
        
    $data curl_exec($ch);
        
    curl_close($ch);
        
        
    $doc = new SimpleXmlElement($dataLIBXML_NOCDATA);
        function 
    parseRSS($xml$u$net$brnch)
    {
       
        
    $cnt count($xml->channel->item);
        for(
    $i=0$i<$cnt$i++)
        {
        
    $url     $xml->channel->item[$i]->link;
        
    $title     $xml->channel->item[$i]->title;
        
    $desc $xml->channel->item[$i]->description;
        
    $date $xml->channel->item[$i]->pubDate;
         
         
    $isitthere mysql_query("SELECT * FROM `data` WHERE data.title = '".$title."' AND data.date = '".$date."' AND data.user = '".$u."'");
         
    $counter 0;
         
         while(
    $isrow mysql_fetch_array($isitthere)) {
             
    $counter ++;
         }
         
         if(
    $counter == '0') {
         
        
    mysql_query("INSERT INTO data VALUES ( NULL, '$title', '$desc', '$date', '$u', '$net', '$brnch' )");
        
        }
        }
    }


        if(isset(
    $doc->channel))
        {
            
    parseRSS($doc$u$net$brnch);
        }
        

        }
    ?>
    Could it be that it's inside a function? I don't see how, because the one below is working...
    Last edited by the-dream; 08-13-2008 at 11:36 AM. Reason: Opps! Left my DB info in! Eeek!

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    None of your mysql_ statements have any error checking logic to get them to tell you if they failed or not and why they failed.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    move the function out side of the while loop too surprised it isn't erroring on redeclaring function
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #6
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Oh my god, I am an idiot.

    addslashes();

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    If your least post is referring to escaping data put into a query, addslashes() does not escape all the special characters that can break a query. Use mysql_real_escape_string()
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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