Jump to content

PHP/Postgresql and EXISTS function


rhyspaterson

Recommended Posts

Hey guys,

 

I'm trying to put together an INSERT command wherein a person can submit a record into the database through a HTML form. However i want to make sure the data is not already in there (stopping duplicates). The table has four columns;

 

id, extension, description and filetype_group

 

I want to match my variable $fileExtension (which is the $_POST variable from the form) against everything in the 'extension' column.

 

So far i have come up with this:

 

$result = pg_exec ($dbconn, "INSERT into filetype (id, extension, description, filetype_group) VALUES ($fileID,'$fileExtension','$fileDescription','$fileGroup') WHERE not exists (SELECT * FROM filetype WHERE filetype.extension = $fileExtension);");

 

The code works fine up until the WHERE not exists section, where i get syntax errors, but unfortunately i have no idea what's wrong. I was hoping you guys could shed some light.

 

Cheers,

/Rhys

Link to comment
https://forums.phpfreaks.com/topic/58174-phppostgresql-and-exists-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.