By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,742 Members | 773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,742 IT Pros & Developers. It's quick & easy.

Error Unknown column 'quotation' in 'field list'

nomad
Expert 100+
P: 664
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.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include_once("db_connection.php");
  3. include_once("rating_functions.php");
  4. include_once("content_functions.php");
  5.  
  6. if (isSet($_GET['RATED_ID'])) {
  7.   $rated_id = $_GET['RATED_ID'];
  8. }
  9. else if (isSet($_POST['RATED_ID'])) {
  10.   $rated_id = $_POST['RATED_ID'];
  11. }
  12. else {
  13.   $rated_id = 1;
  14. }
  15.  
  16. // create the quote content
  17. $content_box = 
  18.   make_content_box($_SERVER['PHP_SELF'],
  19.                    $rated_id);
  20.  
  21. // create the navigation links
  22. $nav_box = 
  23.   make_next_prev_box($_SERVER['PHP_SELF'],
  24.                      $rated_id);
  25.  
  26. // create the self-submitting ratings box
  27. // (also handles submissions)
  28. $submission_box = 
  29.   make_ratings_box($_SERVER['PHP_SELF'],
  30.                    $rated_id);
  31.  
  32. // create the link to the main ratings page
  33. $ratings_link = 
  34.   "<A HREF=\"all_ratings.php\">See 
  35.    other ratings</A>";
  36.  
  37. // create the actual page
  38. $page_string = <<<EOP
  39. <HTML><HEAD><TITLE>Sample ratable page</TITLE></HEAD>
  40. <BODY>
  41. <CENTER><H2>Quote of the moment</H2></CENTER>
  42. <TABLE WIDTH=500 VALIGN=TOP CELLPADDING=20>
  43. <TR VALIGN=TOP>
  44. <TD VALIGN=TOP COLSPAN=50%>
  45. $content_box
  46. <CENTER>$nav_box</CENTER>
  47. </TD><TD ALIGN=TOP COLSPAN=50%>
  48. $submission_box
  49. <BR>$ratings_link
  50. </TD></TR></TABLE>
  51. </BODY></HTML>
  52. EOP;
  53. echo $page_string;
  54. ?>
  55.  
db_connection.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("dbvars.php"); // sets $host, $user, $pass
  3. mysql_connect($hostname, $user, $password)
  4.   or die("Could not connect to database");
  5. mysql_select_db("user_ratings");
  6. ?>
dbvars.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $hostname = "localhost";
  3. $user = "nomad";
  4. $password = "nomad";
  5. ?>
content_functions.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. function make_content_box($current_page, $content_id) {
  4.   $query = 
  5.     "select quotation, attribution from quotations
  6.        where ID = $content_id";
  7.   $result = mysql_query($query) or die(mysql_error());
  8.   if ($row = mysql_fetch_row($result)) {
  9.     $quotation = $row[0];
  10.     $attribution = $row[1];
  11.     $return_string .= 
  12.        "<table align=top><tr align=top>
  13.         <td>\"$quotation\"<br>
  14.         --- $attribution</td></tr></table>";
  15.     return($return_string);
  16.   }
  17.   else {
  18.     return("No content in database");
  19.   }
  20. }
  21.  
  22. function make_next_prev_box ($current_page, $current_id) {
  23.   $prev_id = prev_content_id($current_id);
  24.   $next_id = next_content_id($current_id);
  25.   return("<TABLE><TR><TD>
  26.           <A HREF=\"$current_page?RATED_ID=$prev_id\">Prev quote</A>
  27.           </TD><TD>
  28.           <A HREF=\"$current_page?RATED_ID=$next_id\">Next quote</A>
  29.           </TD></TR></TABLE>");
  30. }
  31.  
  32. function next_content_id ($current_id) {
  33.   $query = "select ID from quotations 
  34.             where ID > $current_id 
  35.             order by ID asc";
  36.  
  37.   $result = mysql_query($query)
  38.     or die("MySQL rejected query $query" . mysql_error());
  39.   if (mysql_num_rows($result) > 0) {
  40.     $row = mysql_fetch_row($result) or die(mysql_error());
  41.     $id = $row[0];
  42.   }
  43.   else {
  44.     $query = "select min(ID) from quotations";
  45.     $result = mysql_query($query) or die(mysql_error());
  46.     $row = mysql_fetch_row($result) or die(mysql_error());
  47.     $id = $row[0];
  48.   }
  49.   return($id);  
  50. }
  51.  
  52. function prev_content_id ($current_id) {
  53.   $query = "select ID from quotations 
  54.             where ID < $current_id 
  55.             order by ID desc";
  56.   $result = mysql_query($query) 
  57.      or die("MySQL rejected query $query" . mysql_error());
  58.   if (mysql_num_rows($result) > 0) {
  59.     $row = mysql_fetch_row($result) or die(mysql_error());
  60.     $id = $row[0];
  61.   }
  62.   else {
  63.     $query = "select max(ID) from quotations";
  64.     $result = mysql_query($query) or die(mysql_error());
  65.     $row = mysql_fetch_row($result) or die(mysql_error());
  66.     $id = $row[0];
  67.   }
  68.   return($id);  
  69. }
  70.  
  71. function truncate_quotation ($quotation) {
  72.   if (strlen($quotation) < 40) {
  73.     return($quotation);
  74.   }
  75.   else {
  76.     $broken_by_punctuation =
  77.       strtok($quotation, ".,!?");
  78.     return("$broken_by_punctuation ...");
  79.   }
  80.  
  81. }
  82.  
  83. ?>
That's it if you need the db information please let me know.
Any help with this would be great.

Nomad
Dec 10 '09 #1

✓ answered by kovik

"Unknown column 'quotation'" is a MySQL error. It is coming from a mysql_query() call, and telling you that you are attempting to use a column named "quotation" in a query, but that the column does not exist.

The culprit looks like it's this query:
Expand|Select|Wrap|Line Numbers
  1. select quotation, attribution from quotations where ID = $content_id
This suggests that your database table "quotations" does not have a field with the name "quotation." However, you did not provide your database table structure, so I can't say for sure.

Check the quotations table to see if there is a column named "quotation." I doubt it. ;)

Share this Question
Share on Google+
3 Replies


kovik
Expert 100+
P: 1,044
"Unknown column 'quotation'" is a MySQL error. It is coming from a mysql_query() call, and telling you that you are attempting to use a column named "quotation" in a query, but that the column does not exist.

The culprit looks like it's this query:
Expand|Select|Wrap|Line Numbers
  1. select quotation, attribution from quotations where ID = $content_id
This suggests that your database table "quotations" does not have a field with the name "quotation." However, you did not provide your database table structure, so I can't say for sure.

Check the quotations table to see if there is a column named "quotation." I doubt it. ;)
Dec 11 '09 #2

nomad
Expert 100+
P: 664
Kovik:
That was it I had a column named "quotations".
infact I made two column name mistakes.

Thanks for the help
Dec 11 '09 #3

kovik
Expert 100+
P: 1,044
No problem at all. Expert to expert, eh? :P
Dec 11 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.