473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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>
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 7802
6,050 Expert 4TB
I imagine there should be a comma following the nextval() call.
Jan 22 '10 #2
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')";
  3. 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.

Jan 22 '10 #3

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

Similar topics

by: Ivo Anon | last post by:
I'm new to postgresql and I'm having problems with the 'nextval' function (or whatever it is called in postgresql). I created a table (called ADDRESS) using 'pgadmin' which has a serial field...
by: Errol Neal | last post by:
Hi all, Not sure if this is a question for a php list or this one, but I'll give it a shot and if I am wrong, please do not crucify me. :-) There is a php based sourceforge project called...
by: Mark Harrison | last post by:
I have indexed two columns in a table. Can somebody explain to me why the first query below uses an Index Scan while the second uses a Seq Scan? Many TIA! Mark planb=# \d abcs Table...
by: Marty Scholes | last post by:
I may have found a bug. I have a table: CREATE TABLE onlpcd_stat ( sel BIGSERIAL PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES onlpcd_user ON DELETE CASCADE, vars TEXT, /*...
by: Kuti Attila | last post by:
Hi, I have a pgplsql function. It is quite short and simple. The problem:
by: Prabu Subroto | last post by:
Dear my friends... I am using postgres 7.4 and SuSE 9.1. I want to use auto_increment as on MySQL. I look up the documentation on www.postgres.com and I found "serial" . But I don't know...
by: Florian G. Pflug | last post by:
Hi Since sometime yesterday, my postgresql (7.4.5) reports "ERROR: cannot compare arrays of different element types", when I analyze a specific table in my database. Here is the tables...
by: Dale Strickland-Clark | last post by:
Now that OIDs have been deprecated in PostgreSQL, how do you find the key of a newly inserted record? I've tried three Python client libraries, including psycopg2, and where they support cursor...
by: serid | last post by:
Hi everyone ! I'm new to PostgreSQL and I'm just reading about sequences. If a sequence is created with upper and lower letters, e.g. create sequence "MySeq" then when one want to use it,...
by: zottty | last post by:
Dear Friends, I guess the problem I am prosting right now should be quite trivial, but nevertheless I'm experienced with SQL, this does not stand for PostgreSQL. I have a table with the...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.