473,387 Members | 1,624 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,387 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 7804
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

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

Similar topics

0
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...
11
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...
3
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...
0
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, /*...
2
by: Kuti Attila | last post by:
Hi, I have a pgplsql function. It is quite short and simple. The problem:
12
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...
2
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...
12
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...
1
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,...
4
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...
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.