-
<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_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... ^
2 7804
I imagine there should be a comma following the nextval() call.
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 -
$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
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: 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:
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...
|
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: 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
|
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: 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,...
|
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,...
|
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...
| |