I hate mysql :mad:
this is the file. I wanted to edit it so that I can use it for all tables and now I got this:
<?php
$contentwidth = "700";
$table = $_GET["table"];
$what = "News";
$title = "News";
$page = "item.php";
include("header.php");
include('news/db.php');
$id = $_GET["id"];
if (isset($_GET["table"])){
if (isset($_GET["id"])){
$query = "SELECT * FROM $table WHERE id = $id ";
$result = mysql_query($query) OR die('Error: ' . mysql_error()); //always use a comprehensive DIE statement so you know WHY you are erroring
} else {
echo "no item selected";
}
} else {
echo"no table selected";
}
// That queries the database
echo "<br><br>";
while($r=mysql_fetch_array($result)){
//vars
$classified = $r["classified"];
$title = $r["title"];
$news = $r["news"];
$body = nl2br($news);
$author = $r["author"];
$link = "mailto:".$r["email"];
$date = $r["date"];
if($table == 'td_downloads') {
$download = $r["link"];
}
if($classified == 'yes') {
if($userdata['session_logged_in']){
//show item
echo "<table width=$contentwidth border=0 cellpadding=0 cellspacing=0>
<tr>
<td height=\"30\" width=\"21\" background=\"images/leftup.png\"></td>
<td height=\"30\" colspan=\"3\" background=\"images/up.png\">$what</td>
<td height=\"30\" width=\"21\" background=\"images/rightup.png\"></td>
</tr>
<tr>
<td width=\"21\" background=\"images/left.png\"></td>
<td colspan=3 background=\"images/spacer_content.png\">
<font class=\"news\">Category: <font class=\"fakelinknews\">$what</font><br>
<font class=\"fakelinknews\">\"$title\"</font> posted by <a class=\"linknews\" href=\"$link\">$author</a>
on <font class=\"fakelinknews\">$date</font></font><br><br>$body";
if($table == 'td_downloads') {
echo "<br><a href=\"$download\">Download</a>";
}
echo "
</td>
<td width=\"21\" background=\"images/right.png\"></td>
</tr>
<tr>
<td height=\"30\" width=\"21\" background=\"images/leftdown.png\"></td>
<td height=\"30\" colspan=\"3\" background=\"images/down.png\"></td>
<td height=\"30\" width=\"21\" background=\"images/rightdown.png\"></td>
</tr>
</table>
";
mysql_close($cnx);
} else {
echo "This information is classified. Please log in or register!";
}
} else {
//show item
echo "<table width=$contentwidth border=0 cellpadding=0 cellspacing=0>
<tr>
<td height=\"30\" width=\"21\" background=\"images/leftup.png\"></td>
<td height=\"30\" colspan=\"3\" background=\"images/up.png\">$what</td>
<td height=\"30\" width=\"21\" background=\"images/rightup.png\"></td>
</tr>
<tr>
<td width=\"21\" background=\"images/left.png\"></td>
<td colspan=3 background=\"images/spacer_content.png\">
<font class=\"news\">Category: <font class=\"fakelinknews\">$what</font><br>
<font class=\"fakelinknews\">\"$title\"</font> posted by <a class=\"linknews\" href=\"$link\">$author</a>
on <font class=\"fakelinknews\">$date</font></font><br><br>$body";
if($table == 'td_downloads') {
echo "<br><a href=\"$download\">Download</a>";
}
echo "
</td>
<td width=\"21\" background=\"images/right.png\"></td>
</tr>
<tr>
<td height=\"30\" width=\"21\" background=\"images/leftdown.png\"></td>
<td height=\"30\" colspan=\"3\" background=\"images/down.png\"></td>
<td height=\"30\" width=\"21\" background=\"images/rightdown.png\"></td>
</tr>
</table>
";
mysql_close($cnx);
}
}
?>
<? include("footer.php"); ?>
This is the error:
Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = 3' at line 1
It seems that the variables didn't get passed from the get vars to
$id and $table 😕
and also: (and I did define the table variable!)
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site51/fst/var/www/html/td/main/header.php on line 152
help is appreciated 🙂