www.webdeveloper.com
Results 1 to 15 of 15

Thread: How to show news? Erorr message...Need help

  1. #1
    Join Date
    Sep 2005
    Posts
    1,635

    Question How to show news? Erorr message...Need help

    I would like to read all articles in rows.

    Do you know why it gives me error
    Warning: link(): Permission denied in ...read_article.php on line 55
    Line 55 is:
    PHP Code:
    echo '<td><A HREF="'.link("article.php""ID=".$_GET['id']).'"><B>'.$rec[$i].'</B></A></td>'

    code is:
    PHP Code:
    <?  

    # Param 1 : MySQL Host Name
    # Param 2 : MySQL Username
    # Param 3 : MySQL Password
    # Param 4 : MySQL Database
    # Param 5 : SQL Statement (SELECT)

    show_table("localhost","...","...","...","SELECT * FROM articles");

    function 
    show_table($hostName,$userName,$passWord,$dataBase,$sqlQuery)
    {
        
    # Connect to MySQL
        
    $conn=mysql_connect("...""...""...");
        
    # Select Database
        
    mysql_select_db($dataBase,$conn);
        
    # Validate SQL Statement
        
    $array=explode(" ORDER",$sqlQuery);
        
    $sqlQuery=$array[0];
        if(!
    strstr($sqlQuery,"SELECT"))
            die(
    "Invalid Query : SQL statement should be a SELECT statement.");
        
    # ORDER records by requested column
        
    if($_GET['order'])
            
    $sqlQuery=$sqlQuery." ORDER BY ".$_GET['order'];
        
    # Execute SQL query
        
    $result=mysql_query($sqlQuery) or die("Invalid Query : ".mysql_error());
        
    $row=mysql_fetch_array($result);
        
    # Check whether NULL records found
        
    if(!mysql_num_rows($result))
            die(
    "No records found.");

        echo 
    "<table border=1><tr>";
        
    # Make the row for table column names
        
    while (list($key$value) = each($row))
        {
            
    $i++;
            if(!(
    $i%2))
               echo 
    "<td><b><a href='?order=$key'>$key</a></td>";
        }
        echo 
    "</tr>";
        
    $result=mysql_query($sqlQuery);

        
    // Make rows for records
        
    while($rec=mysql_fetch_array($result))
        {
            echo 
    "<tr>";
            for(
    $i=0;$i<count($rec);$i++)
            {
                if(
    $rec[$i])
                    echo 
    '<td><A HREF="'.link("article.php""ID=".$_GET['id']).'"><B>'.$rec[$i].'</B></A></td>';

            }
            echo 
    "</tr>";
        }
        echo 
    "</table>";
    }
    ?>

  2. #2
    Join Date
    Mar 2006
    Posts
    52

    Lightbulb Link

    Link si trying to create a hardlink on your system ...

    1. Do you use windows?
    2. if (!1) do you have the necesary rights there ?

    Best Regards
    Adrian

    P.S. http://www.php.net/manual/en/function.link.php

  3. #3
    Join Date
    Sep 2005
    Posts
    1,635
    I would like to read all articles in rows with all coloumns from server (table).

    Each row should have link to e.g. www.mywebsite.com/article?ID=1 in the first row and in second row e.g. www.mywebsite.com/article?ID=2

    Number should change with articles ID number (ID for article is in table in first field).
    Last edited by toplisek; 03-26-2006 at 01:48 AM.

  4. #4
    Join Date
    Mar 2006
    Posts
    52

    Lightbulb

    Your program is trying to do a hard link in your system. Try to change that and will work or gove the right permisions on the system. If you are under *nix try to chmod with the owner of your webserver (under debian linux the owner is www-data on other system is apache or www)


    Best Regards
    A.
    P.S. I dont know what is doing your code but try in this way if you are not want to using the "link" (I don't know why you are using link there ? do you declared a function named link ? php have it's own function link and you cannot declare a function with the same name):

    PHP Code:
    echo '<td><A HREF="'article.php?ID='.$_GET['id'].'"><B>'.$rec[$i].'</B></A></td>'; 

  5. #5
    Join Date
    Sep 2005
    Posts
    1,635

    Question

    I have solved and it works now. Problem was in href=""
    PHP Code:
        echo '<td><a href="article.php?ID='.$_GET['id'].'"><B>'.$rec[$i].'</B></A></td>'
    Do you know how to get $_GET['id'] form table on server where is ID first column?
    Last edited by toplisek; 03-26-2006 at 02:07 AM.

  6. #6
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    your query on the article.php page would be something this...

    PHP Code:
    <?php

    $q 
    "SELECT field,field,field FROM table where id = '".$_GET['ID']."' ";
    $s mysql_query($q);
    echo(
    mysql_error($s));

     
    $r mysql_fetch_assoc($s);

    //echo the title
    echo("<h1>".$r['title']."</h1><br>"."\n");
    //echo the artcile
    echo("<p>".$r['article']."</p>");

    ?>

  7. #7
    Join Date
    Sep 2005
    Posts
    1,635
    I have put while sentence :
    PHP Code:

        
    // Make rows for records
        
    while($rec=mysql_fetch_array($result))
        {
           echo 
    "<tr>";
            for(
    $i=0;$i<count($rec);$i++)
            {
                if(
    $rec[$i])


    $query "SELECT ID FROM articles where ID = '$rec[$i]' ";
    $s mysql_query($query);
    echo(
    mysql_error($s));

    $result mysql_fetch_assoc($s);
    $ID=$result['ID'];
    //echo the article
    //echo("<p>".$result['ID']."</p>");


                
    echo '<td><a href="article.php?ID='.$ID.'"><B>'.$rec[$i].'</B></A></td>';
            }
            echo 
    "</tr>";
        }
        echo 
    "</table>";

    It gives me error:
    Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 59

    Line 59 is:
    echo(mysql_error($s));
    Do you know how is correct to get ID number in this while sentence? Need help

  8. #8
    Join Date
    Mar 2006
    Posts
    52

    Lightbulb

    Quote Originally Posted by toplisek
    I have put while sentence :
    PHP Code:

        
    // Make rows for records
        
    while($rec=mysql_fetch_array($result))
        {
           echo 
    "<tr>";
            for(
    $i=0;$i<count($rec);$i++)
            {
                if(
    $rec[$i])


    $query "SELECT ID FROM articles where ID = '$rec[$i]' ";
    $s mysql_query($query);
    echo(
    mysql_error($s));

    $result mysql_fetch_assoc($s);
    $ID=$result['ID'];
    //echo the article
    //echo("<p>".$result['ID']."</p>");


                
    echo '<td><a href="article.php?ID='.$ID.'"><B>'.$rec[$i].'</B></A></td>';
            }
            echo 
    "</tr>";
        }
        echo 
    "</table>";

    It gives me error:
    Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 59

    Line 59 is:
    echo(mysql_error($s));
    Do you know how is correct to get ID number in this while sentence? Need help

    After $query="Select ...." ; add a new line with :
    echo $query."<br>";
    and post the result of this echo here on forum.

    Best Regards
    Adrian

  9. #9
    Join Date
    Sep 2005
    Posts
    1,635
    I have put echo $query."<br>";

    and result is as following:
    SELECT * FROM articles where ID = '1'

    Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 57
    SELECT * FROM articles where ID = '2006-03-16'

    Line 57 is: echo(mysql_error($s));

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result .../read_news.php on line 48

    Line 48 is while($rec=mysql_fetch_array($result))

  10. #10
    Join Date
    Mar 2006
    Posts
    52

    Lightbulb

    Only now I see you are using the same variablie name for :
    while($rec=mysql_fetch_array($result))
    and
    $result = mysql_fetch_assoc($s);


    try to use another varable name and I guarantee will work for example:
    $result2 = mysql_fetch_assoc($s);

    and change that on all where you used.

    Best Regards
    Adrian

    myDomainTracker

  11. #11
    Join Date
    Sep 2005
    Posts
    1,635

    Question

    Now it shows all but I have problem that if I put code for error
    like
    PHP Code:
     echo(mysql_error($s)); 
    , it will be full of errors:
    Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 57

    Line 57 is: echo(mysql_error($s));

    Problem is that is still not solved link for each column like:
    http://www.mywebsite/article.php?ID=1
    http://www.mywebsite/article.php?ID=2
    http://www.mywebsite/article.php?ID=3
    and ....

    Now is shown correct link just for first column where is ID, but I have four more columns...
    Last edited by toplisek; 03-26-2006 at 01:59 PM.

  12. #12
    Join Date
    Mar 2006
    Posts
    52

    Lightbulb

    try to comment that line or use it in this way attached by your query.

    $result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

    Anyway if you have a error your php will report that.

    The problem with links:

    Before echo "<tr>"; add echo count($rec)."<br>";

    and tell me the result;

    Best Regards
    Adrian

  13. #13
    Join Date
    Sep 2005
    Posts
    1,635

    Question

    There is no error shown. Problem is:
    1.it gives me just first row
    2.only first column has correct link like:
    http://mywebsite/article.php?id=1
    It should have all columns above link

    I have put echo count($rec)."<br>"; and number is 14

  14. #14
    Join Date
    Mar 2006
    Posts
    52
    1. you looked at your generated html source ?
    2. Is possible to have incorect links in database ?
    3. Is possible to see this link somwhere in internet ? (send on private)
    4. Is possible to have incorect html tags ?

    Best Regards
    Adrian

  15. #15
    Join Date
    Sep 2005
    Posts
    1,635

    Question

    Quote Originally Posted by sacx13
    1. you looked at your generated html source ?
    Please explain question...

    Quote Originally Posted by sacx13
    2. Is possible to have incorect links in database ?
    Links are correct for first row and first column.
    It should generate link as I quoted

    Quote Originally Posted by sacx13
    3. Is possible to see this link somwhere in internet ? (send on private)
    No, it is testing server which is not visible on internet

    Quote Originally Posted by sacx13
    4. Is possible to have incorect html tags ?
    What do you mean?
    Best Regards
    Adrian

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles