Click to See Complete Forum and Search --> : How to show news? Erorr message...Need help
toplisek
03-24-2006, 06:48 AM
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:
echo '<td><A HREF="'.link("article.php", "ID=".$_GET['id']).'"><B>'.$rec[$i].'</B></A></td>';
code is:
<?
# 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>";
}
?>
sacx13
03-24-2006, 04:18 PM
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
toplisek
03-25-2006, 12:54 AM
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).
sacx13
03-25-2006, 03:12 AM
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):
echo '<td><A HREF="'article.php?ID='.$_GET['id'].'"><B>'.$rec[$i].'</B></A></td>';
toplisek
03-26-2006, 01:49 AM
I have solved and it works now. Problem was in href=""
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?
Sheldon
03-26-2006, 02:17 AM
your query on the article.php page would be something this...
<?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>");
?>
toplisek
03-26-2006, 05:04 AM
I have put while sentence :
// 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
sacx13
03-26-2006, 09:33 AM
I have put while sentence :
// 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
toplisek
03-26-2006, 09:46 AM
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))
sacx13
03-26-2006, 12:36 PM
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 (http://www.mydomaintracker.net)
toplisek
03-26-2006, 01:53 PM
Now it shows all but I have problem that if I put code for error
like
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...
sacx13
03-26-2006, 02:09 PM
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
toplisek
03-27-2006, 02:32 AM
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
sacx13
03-27-2006, 05:42 AM
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
toplisek
03-27-2006, 06:07 AM
1. you looked at your generated html source ?
Please explain question...
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
3. Is possible to see this link somwhere in internet ? (send on private)
No, it is testing server which is not visible on internet
4. Is possible to have incorect html tags ?
What do you mean?
Best Regards
Adrian