Hello,
I'm working on this tutorial, it's a baisc "news" board. Basically I'm putting data into a MySQL database, getting it out, and displaying it on a page. Pretty standard stuff. However, sense I'm pretty new and haven't fully got a grasp on it all, I need help with this problem.
Here's the script to get data out:
<html>
<head>
<title>Getting Data Out of the Database</title>
</head>
<body bgcolor="#FFFFFF">
<h1>The Daily News</h1>
Order News By:
<a href="data_out.php?orderby=date">Date</a>,
<a href="data_out.php?orderby=heading">Heading</a> or by
<a href="data_out.php?orderby=author">Author</a>.
<p>
<form action="data_out.php" method="POST">
Or only see articles written by (</i>enter author name</i>):
<input type="text" name="author">
<input type="submit" name="submit" value="submit!">
</form>
<table border="1" cellpadding="3">
<?php
/ This program gets news items from the database /
$db = mysql_connect("localhost", "root");
mysql_select_db("php3", $db);
if ($orderby == 'date'):
$sql = "select from news order by 'date'";
elseif ($orderby == 'author'):
$sql = "select from news order by 'author_name'";
elseif ($orderby == 'heading'):
$sql = "select from news order by 'heading'";
elseif (isset($submit)):
$sql = "select from news where author_name = '$author'";
else:
$sql = "select * from news";
endif;
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
print("<tr><td bgcolor=\"#003399\"><b>");
printf("<font color=\"white\">%s</font></b></td></tr>\n",
$row["heading"]);
printF("<td>By: <a href=\"mailto:%s\">%s</a>\n",
$row["author_email"], $row["author_name"]);
printf("<br>Posted: %s<hr>\n",
$row["date"]);
printf("%s</td></tr>\n",
$row["body"]);
}
?>
</table>
</body>
</html>
and I get this nice error:
<B>Warning</b>: Supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\php\messageboard\data_out.php on line 34
I can't figure it out. It seems to me that the SQL queries are fine. Can anyone help?