PostgreSQL error: type "nextval" does not exist.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sshade25
    New Member
    • Nov 2009
    • 10

    PostgreSQL error: type "nextval" does not exist.

    Code:
    <html>
        <body>
    <?php
     $PGHOST = localhost;
     $PGDATABASE = "SantaRosaDB";
     $PGUSER = "postgres";
     $PGPASSWORD = "Casabubu25";
     $PGPORT = 5432;
     $db_handle = pg_connect("dbname=$PGDATABASE user=$PGUSER
     password=$PGPASSWORD");
     if ($db_handle) {
     echo 'Connection attempt succeeded.';
     } else {
     echo 'Connection attempt failed.';
     }
     $cropid = intval( $_POST['cropid']);  
     $crop_type = pg_escape_string($_POST['crop_type']);
     $crop_name = pg_escape_string($_POST['crop_name']);
     $cultivation_yrs = intval( $_POST['local_names']);
     $local_name = pg_escape_string($_POST['cultivation_yrs']);
     $query = "INSERT INTO crops (cropid,crop_type,crop_name,local_name, cultivation_yrs)VALUES(nextval('cropid_seq') '$crop_type', '$crop_name', '$local_name', '$cultivation_yrs')";
     $result = pg_query($query);
     if (!$result) {
     $errormessage = pg_last_error();
     echo "Error with query: " . $errormessage;
     exit();
     }
     printf ("These values were inserted into the database - %s %s %s %s %s",$crop_id,$crop_type,$crop_name,$cultivation_yrs,$local_name);
     pg_close();
    ?>
      </body>
     </html>
    The script is written to populate a postgresql database table using an html form but it is giving me the error below.

    Warning: pg_query() [function.pg-query]: Query failed: ERROR: type "nextval" does not exist LINE 1: ...type,crop_na me,local_name, cultivation_yrs )VALUES(nextval ('c... ^ in C:\ms4w\Apache\ htdocs\php\inpu tcrops.php on line 22
    Error with query: ERROR: type "nextval" does not exist LINE 1: ...type,crop_na me,local_name, cultivation_yrs )VALUES(nextval ('c... ^
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I imagine there should be a comma following the nextval() call.

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      Hey I dont know anything about postgresql database but the query line is quite interesting
      $query = "INSERT INTO crops (cropid,crop_ty pe,crop_name,lo cal_name, cultivation_yrs )VALUES(nextval ('cropid_seq') '$crop_type', '$crop_name', '$local_name', '$cultivation_y rs')";
      you have used nextval function. Make sure this function does exists in postgresql database(I guess it does not). another strategy you can apply to figure out the bug

      Code:
      $query = "INSERT INTO crops (cropid,crop_type,crop_name,local_name, cultivation_yrs)VALUES(nextval('cropid_seq') '$crop_type', '$crop_name', '$local_name', '$cultivation_yrs')";
      
      echo "<br>".$query."<br>";
      after that run the browser and run the site. then from browser copy the query. Then run it from the database client. You will get more information about your error and also be able to figure out what is happening faster.

      Regards,
      Johny

      Comment

      Working...