Warning: mysql_fetch_assoc(): supplied argument
Hi I'm a php novice and for some reason I keep getting an error like this:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
C:\wamp\www\ccfnewsarticle\index.php on line 34
when I use a conditional statement to test the querys I get this error:
Could not successfully run query (SELECT id, name, posted, summary, author_name,
author_email FROM news_articles ORDER BY posted DESC LIMIT 0, 10 ) from DB: No database
selected
Here is the code
<?php
//verbus newsletter
// index.php - Displays summaries of the most recent articles
$hostname = 'localhost';
$username = 'vcounts';
$password = ''; //no password yet
$database = 'cffnews';
$mysql = mysql_connect($hostname, $username, $password);
mysql_select_db($database);
$sql = "SELECT id, name, posted, summary, author_name, author_email ";
$sql .= "FROM news_articles ";
$sql .= "ORDER BY posted DESC ";
$sql .= "LIMIT 0, 10 ";
$result = mysql_query($sql);
/*
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
*/
?>
<h1>Fresh off the Press!</h1>
<?php
while($row = mysql_fetch_assoc($result)) {
$id = $row['id'];
$name = $row['name'];
$posted = $row['posted'];
$summary = $row['summary'];
$author_name = $row['author_name'];
$author_email = $row['author_email'];
$mail_link = "mailto:$author_email";
$read_link = "article.php?id=$id";
echo "<h2>$name</h2>";
echo "<p>Posted By <a href=\"$mail_link\">$author_name</a> on $posted</p>";
echo "<p>$summary</p>";
echo "<p>To read more <a href=\"$read_link\">Click Here</a></p>";
echo "<hr />";
}
?>
Here is the database code
CREATE TABLE news_articles (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(65) NOT NULL DEFAULT 'Untitled Article',
posted DATETIME NOT NULL,
summary TEXT NOT NULL,
content TEXT NOT NULL,
author_name VARCHAR(65) NOT NULL DEFAULT 'Anonymous Author',
author_email VARCHAR(128) DEFAULT NULL,
PRIMARY KEY(id)
);
CREATE TABLE images(
id INT NOT NULL AUTO_INCREMENT,
thumb VARCHAR(65) NOT NULL,
image VARCHAR(65) NOT NULL,
caption VARCHAR(128) NOT NULL,
PRIMARY KEY(id)
);
What is going on here HELP!!!!!!!
|