Error Unknown column 'quotation' in 'field list'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    Error Unknown column 'quotation' in 'field list'

    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
    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;
    ?>
    db_connection.p hp
    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");
    ?>
    dbvars.php
    Code:
    <?php
    $hostname = "localhost";
    $user = "nomad";
    $password = "nomad";
    ?>
    content_functio ns.php
    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 ...");
      }
    
    }
    
    ?>
    That's it if you need the db information please let me know.
    Any help with this would be great.

    Nomad
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    "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:
    Code:
    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. ;)

    Comment

    • nomad
      Recognized Expert Contributor
      • Mar 2007
      • 664

      #3
      Kovik:
      That was it I had a column named "quotations ".
      infact I made two column name mistakes.

      Thanks for the help

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        No problem at all. Expert to expert, eh? :P

        Comment

        Working...