I am attempting to Insert a value into a Foreign Key column in a postgresql table. I am in the databases forum with this one too! I was wondering if there is anything in PHP I am doing wrong when passing the variables in, this is my code:
include("classes/dbConnector.class.php");
//create an object of the dbConnector class
$db = new dbConnector();
$conn_string = "host=127.0.0.1 port=5432 dbname=filemanager user=pgsql password=postgres";
$connect = $db->dbConnect($conn_string);
if (!$connect)
{
die("Could not open connection to database server");
}
$query = "INSERT INTO directories (directoryname,datecreated,uid) VALUES ('$newdir',now(),'$uid')";
$result = $db->dbExecQuery($connect, $query) or die("Error in query: $query . " . pg_last_error($connect));
//close database connection
$db->dbClose($connect);
This is the Error I am recieving:
Warning: pg_last_error(): 1 is not a valid PostgreSQL link resource in /usr/local/www/data-dist/filemanager/makedir.php on line 81
Error in query: INSERT INTO directories (directoryname,datecreated,uid) VALUES ('hello',now(),'1') .
Can anyone help?
Inserting into a Database
Moderator: General Moderators
Exactly what is on line 81? The link id reffers to the connection to the db, I guess your connection string is correct. Can you retrieve info from the db, just a simple SELECT * FROM db will do.
Also notice the now() in the error message.
Also notice the now() in the error message.
That should be a time/date value. Escape the string to have it use the value, rather than the string.INSERT INTO directories (directoryname,datecreated,uid) VALUES ('hello',now(),'1') .
Code: Select all
$query = "INSERT INTO directories (directoryname,datecreated,uid) "
.= "VALUES ('$newdir', " .now(). ",'$uid')";Thanks for that.
I have tried that, with no joy.
This is the new Error:
Fatal error: Call to undefined function: now() in /usr/local/www/data-dist/filemanager/makedir.php on line 81
I thought to myself, can I replicate the Postgresql datetime using the following:
$today = date("Y-m-d H:i:s");
And ALTER the directories table 'datecreated' field to 'varchar'?
So I tried that, but got this error again:
Warning: pg_last_error(): 1 is not a valid PostgreSQL link resource in /usr/local/www/data-dist/filemanager/makedir.php on line 83
Error in query: INSERT INTO directories (directoryname,datecreated,uid) VALUES ('hello', '2002-12-19 12:17:02','1') .
This is line 83:
$result = $db->dbExecQuery($connect, $query) or die("Error in query: $query . " . pg_last_error($connect));
Is there any flaws?
Help, this is starting to ruin my Christmas.....
I have tried that, with no joy.
This is the new Error:
Fatal error: Call to undefined function: now() in /usr/local/www/data-dist/filemanager/makedir.php on line 81
I thought to myself, can I replicate the Postgresql datetime using the following:
$today = date("Y-m-d H:i:s");
And ALTER the directories table 'datecreated' field to 'varchar'?
So I tried that, but got this error again:
Warning: pg_last_error(): 1 is not a valid PostgreSQL link resource in /usr/local/www/data-dist/filemanager/makedir.php on line 83
Error in query: INSERT INTO directories (directoryname,datecreated,uid) VALUES ('hello', '2002-12-19 12:17:02','1') .
This is line 83:
$result = $db->dbExecQuery($connect, $query) or die("Error in query: $query . " . pg_last_error($connect));
Is there any flaws?
Help, this is starting to ruin my Christmas.....
OK, there is no function called now(), it seemed right and is used in other languages, but what you have done looks all right.
Your database column should be type date instead of varchar.
I see you have made you own connection class. What is the code you have written for dbExecQuery?
Your database column should be type date instead of varchar.
I see you have made you own connection class. What is the code you have written for dbExecQuery?
Last edited by f1nutter on Thu Dec 19, 2002 5:32 am, edited 1 time in total.
PHP Bugs
Have found an answer to my problems:
http://p2p.wrox.com/archive/pro_php/2000-12/11.asp
Might be worth a read if you're interested in PHP bugs
http://p2p.wrox.com/archive/pro_php/2000-12/11.asp
Might be worth a read if you're interested in PHP bugs