need help updating old PHP script

Discussion in 'PHP' started by scoopy82, Oct 5, 2008.

  1. #1
    Everything used to work... but that was a long, long, time ago... and there have been many upgrades to PHP and MySQL since I last touched this code and most likely the reason why I am getting errors now.

    The problem I am seeing is:
    The code from the lines referenced look like this:
    $CategoryID[$CategoryCount] = mysql_result($categorysql, 0, "ID");
    $CategoryName[$CategoryCount] = mysql_result($categorysql, 0, "Name");
    $CategoryBelongs[$CategoryCount] = mysql_result($categorysql, 0, "Belongs");
    PHP:
    Has something changed (within past year or two) with this code ? Or do I need to dig any deeper.

    I have tried some simple things that my limited PHP knowledge could come up with... such as single quotes instead of the doubles and adding the "or die" thing that I found posted elsewhere.

    thanks,

    PS: guess I should mention we are running PHP 5.2.6 and mysql 5.0.51a
     
    scoopy82, Oct 5, 2008 IP
  2. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think something wrong with your MySQL query. Can you show us the value of the "$categorysql" variable?
     
    GuitarFix, Oct 5, 2008 IP
  3. scoopy82

    scoopy82 Active Member

    Messages:
    838
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    70
    #3
    That was found right above the previous code I posted:
    $categorysql = mysql_query ("SELECT ID, Name, Belongs FROM category WHERE ID = $ArtCategory");
    Print mysql_error();
    PHP:
    This (i am guessing) points me to:
    $ArtCategory = mysql_result($articlesql, 0, 'Category');
    PHP:
    which then leads me to this line of code:
    $articlesql = mysql_query ("SELECT ID, Category, Author, Email, Title, ArticleBody, ArticleBlurb, DateSub, DateAct, URL, Active FROM articles WHERE ID = $ArticleID AND Active = 1");
    $CheckFound = mysql_num_rows($articlesql);
    If ($CheckFound == 0)
    PHP:
    Are we on the right track or have I fallen off yet?
     
    scoopy82, Oct 5, 2008 IP
  4. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hm..
    Try to use mysql_result() with the first single parametr: mysql_result($articlesql) without "0" and "field name".
     
    GuitarFix, Oct 7, 2008 IP
  5. scoopy82

    scoopy82 Active Member

    Messages:
    838
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    70
    #5
    That change results in changing the error I get.

    From:
    To this:
     
    scoopy82, Oct 7, 2008 IP
  6. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It's so strange.. :)

    Is there an error like this now? "Warning: mysql_result(): supplied argument is not a valid MySQL result resource" ?

    Try to test something like this:
    
    $ArticleID = intval( $ArticleID );
    $articlesql = mysql_query ("SELECT * FROM articles WHERE ID=$ArticleID AND Active=1") or die( mysql_error() );
    
    PHP:
    Is there any warnings with that code?
     
    GuitarFix, Oct 9, 2008 IP
  7. scoopy82

    scoopy82 Active Member

    Messages:
    838
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    70
    #7
    That didn't seem to change anything. SO I started digging around this code some more and figured out that this page in question (articles_new.php) is the same one that is working to display the single articles on the site.

    So that even tho the error messages are pointing to this page... I believe the errant code is from another file.

    Will dig some more.
     
    scoopy82, Oct 10, 2008 IP
  8. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #8
    Add a debuging statement to print the faulty sql that way you can see which statement and where the error arise.
    $result = mysql_query($query) or die('Error ,query failed <br>'.$query);
    Code (markup):
     
    javaongsan, Oct 10, 2008 IP
  9. scoopy82

    scoopy82 Active Member

    Messages:
    838
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    70
    #9
    I get nothing but "Error ,query failed" with that line javaongsan.

    I also found that is the correct page producing the error... and it seems it has to do with the .htaccess file... which has this:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /getarticle/articles_new.php [L,QSA]
    Code (markup):
    Without this code... I get "Page Not Found" errors for everything... So I guess I need to figure out how it is working for the single article pages and not the category listings.

    I am thinking I need to intercept and rewrite the URL for any thing pointing to /category ???

    Digging some more...
     
    scoopy82, Oct 10, 2008 IP
  10. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #10
    did you do
    $query="SELECT ID, Name, Belongs FROM category WHERE ID = $ArtCategory";
    or what ever sql statement you use
     
    javaongsan, Oct 10, 2008 IP
  11. scoopy82

    scoopy82 Active Member

    Messages:
    838
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    70
    #11
    I am really getting lost in all this javaongsan... but I did manage to get "Array" from what your idea... which I think makes sense... the page errors out because it does not have the needed results from the query.

    I believe the issue is path related because...

    I made a copy of the site files in a subfolder and was getting the same errors (not a valid MySQL result) for the single article pages. I needed to change the links and also the line:
    $var_array = explode("/subfolder",$TheURL); 
    Code (markup):
    and
    $GlobalSiteDomain = "/subfolder/";
    Code (markup):
    To reflect the move and this fixed those pages... now only if I can figure out how the category pages are supposed to be displayed.

    Thanks for both your help. We will keep trying things here.
     
    scoopy82, Oct 11, 2008 IP
  12. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #12
    its better you paste the entire code here or you can sent me the source I have look
     
    javaongsan, Oct 11, 2008 IP