Hello everyone:
I new to PHP and I'm reading a book on PHP Bibles 2nd edition. It has to deal with a user-rating system. There are 4 scripts to it.
I'm getting an error
Unknown column 'quotation' in 'field list'
Here is my code
rated_display.p hp
db_connection.p hp
dbvars.php
content_functio ns.php
That's it if you need the db information please let me know.
Any help with this would be great.
Nomad
I new to PHP and I'm reading a book on PHP Bibles 2nd edition. It has to deal with a user-rating system. There are 4 scripts to it.
I'm getting an error
Unknown column 'quotation' in 'field list'
Here is my code
rated_display.p hp
Code:
<?php
include_once("db_connection.php");
include_once("rating_functions.php");
include_once("content_functions.php");
if (isSet($_GET['RATED_ID'])) {
$rated_id = $_GET['RATED_ID'];
}
else if (isSet($_POST['RATED_ID'])) {
$rated_id = $_POST['RATED_ID'];
}
else {
$rated_id = 1;
}
// create the quote content
$content_box =
make_content_box($_SERVER['PHP_SELF'],
$rated_id);
// create the navigation links
$nav_box =
make_next_prev_box($_SERVER['PHP_SELF'],
$rated_id);
// create the self-submitting ratings box
// (also handles submissions)
$submission_box =
make_ratings_box($_SERVER['PHP_SELF'],
$rated_id);
// create the link to the main ratings page
$ratings_link =
"<A HREF=\"all_ratings.php\">See
other ratings</A>";
// create the actual page
$page_string = <<<EOP
<HTML><HEAD><TITLE>Sample ratable page</TITLE></HEAD>
<BODY>
<CENTER><H2>Quote of the moment</H2></CENTER>
<TABLE WIDTH=500 VALIGN=TOP CELLPADDING=20>
<TR VALIGN=TOP>
<TD VALIGN=TOP COLSPAN=50%>
$content_box
<CENTER>$nav_box</CENTER>
</TD><TD ALIGN=TOP COLSPAN=50%>
$submission_box
<BR>$ratings_link
</TD></TR></TABLE>
</BODY></HTML>
EOP;
echo $page_string;
?>
Code:
<?php
include("dbvars.php"); // sets $host, $user, $pass
mysql_connect($hostname, $user, $password)
or die("Could not connect to database");
mysql_select_db("user_ratings");
?>
Code:
<?php $hostname = "localhost"; $user = "nomad"; $password = "nomad"; ?>
Code:
<?php
function make_content_box($current_page, $content_id) {
$query =
"select quotation, attribution from quotations
where ID = $content_id";
$result = mysql_query($query) or die(mysql_error());
if ($row = mysql_fetch_row($result)) {
$quotation = $row[0];
$attribution = $row[1];
$return_string .=
"<table align=top><tr align=top>
<td>\"$quotation\"<br>
--- $attribution</td></tr></table>";
return($return_string);
}
else {
return("No content in database");
}
}
function make_next_prev_box ($current_page, $current_id) {
$prev_id = prev_content_id($current_id);
$next_id = next_content_id($current_id);
return("<TABLE><TR><TD>
<A HREF=\"$current_page?RATED_ID=$prev_id\">Prev quote</A>
</TD><TD>
<A HREF=\"$current_page?RATED_ID=$next_id\">Next quote</A>
</TD></TR></TABLE>");
}
function next_content_id ($current_id) {
$query = "select ID from quotations
where ID > $current_id
order by ID asc";
$result = mysql_query($query)
or die("MySQL rejected query $query" . mysql_error());
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_row($result) or die(mysql_error());
$id = $row[0];
}
else {
$query = "select min(ID) from quotations";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result) or die(mysql_error());
$id = $row[0];
}
return($id);
}
function prev_content_id ($current_id) {
$query = "select ID from quotations
where ID < $current_id
order by ID desc";
$result = mysql_query($query)
or die("MySQL rejected query $query" . mysql_error());
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_row($result) or die(mysql_error());
$id = $row[0];
}
else {
$query = "select max(ID) from quotations";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result) or die(mysql_error());
$id = $row[0];
}
return($id);
}
function truncate_quotation ($quotation) {
if (strlen($quotation) < 40) {
return($quotation);
}
else {
$broken_by_punctuation =
strtok($quotation, ".,!?");
return("$broken_by_punctuation ...");
}
}
?>
Any help with this would be great.
Nomad
Comment