471,594 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

PostgreSQL error: type "nextval" does not exist.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <body>
  3. <?php
  4.  $PGHOST = localhost;
  5.  $PGDATABASE = "SantaRosaDB";
  6.  $PGUSER = "postgres";
  7.  $PGPASSWORD = "Casabubu25";
  8.  $PGPORT = 5432;
  9.  $db_handle = pg_connect("dbname=$PGDATABASE user=$PGUSER
  10.  password=$PGPASSWORD");
  11.  if ($db_handle) {
  12.  echo 'Connection attempt succeeded.';
  13.  } else {
  14.  echo 'Connection attempt failed.';
  15.  }
  16.  $cropid = intval( $_POST['cropid']);  
  17.  $crop_type = pg_escape_string($_POST['crop_type']);
  18.  $crop_name = pg_escape_string($_POST['crop_name']);
  19.  $cultivation_yrs = intval( $_POST['local_names']);
  20.  $local_name = pg_escape_string($_POST['cultivation_yrs']);
  21.  $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')";
  22.  $result = pg_query($query);
  23.  if (!$result) {
  24.  $errormessage = pg_last_error();
  25.  echo "Error with query: " . $errormessage;
  26.  exit();
  27.  }
  28.  printf ("These values were inserted into the database - %s %s %s %s %s",$crop_id,$crop_type,$crop_name,$cultivation_yrs,$local_name);
  29.  pg_close();
  30. ?>
  31.   </body>
  32.  </html>
  33.  
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_name,local_name, cultivation_yrs)VALUES(nextval('c... ^ in C:\ms4w\Apache\htdocs\php\inputcrops.php on line 22
Error with query: ERROR: type "nextval" does not exist LINE 1: ...type,crop_name,local_name, cultivation_yrs)VALUES(nextval('c... ^
Jan 22 '10 #1
2 7613
Markus
6,050 Expert 4TB
I imagine there should be a comma following the nextval() call.
Jan 22 '10 #2
johny10151981
1,059 1GB
Hey I dont know anything about postgresql database but the query line is quite interesting
$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')";
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

Expand|Select|Wrap|Line Numbers
  1. $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')";
  2.  
  3. echo "<br>".$query."<br>";
  4.  
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
Jan 22 '10 #3

Post your reply

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

Similar topics

reply views Thread by Ivo Anon | last post: by
11 posts views Thread by Errol Neal | last post: by
2 posts views Thread by Kuti Attila | last post: by
12 posts views Thread by Prabu Subroto | last post: by
12 posts views Thread by Dale Strickland-Clark | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.