> Joshua Walusz wrote:
> > Hello,
> > Could anyone explain to me why this is not posting data to the PostgreSQL
> > DB???? Please review my code listed below and let me know if you have any
> > suggestions:
> 
> > $query = pg_exec($connection, "INSERT INTO users (username, password,
> > company) VALUES ('$username', '$password', '$company')");


--- Dick Russel <[EMAIL PROTECTED]> wrote:
> Hey Josh,
> I like to issue a die statement when I get strange database errors. This
> way you get the command that is about to execute.
> Just copy the command and paste it into your database client command
> window. Sometimes the DB will give you a more precise error message. And
> if the insert works you know your connection is wrong and not your
> command. I do this for MySQL but this practice should work for
> PostgreSQL as well.
> 
> $sql = "INSERT INTO users (username, password, company) VALUES
> ('$username', '$password', '$company')";
> die("$sql");
> 
> Run the above and paste the output into your SQL client program.

That's good but it will "die" no matter whether the query is successful or not.
 I use MySQL and do something like the code below.  Perhaps you can do
something similar for PGSQL.

$db  = mysql_connect("localhost","dbuser","dbpwd");
mysql_select_db("dbname");
$sql = "some query";
$res = mysql_query($sql,$db) or die(sprintf("%s<hr><pre>%s</pre>",
mysql_error(), $sql));

In this case, the die only runs if the query fails.  Also, for MySQL, it is
often helpful to have newline (\n) characters to break it up on multiple lines.
 This way, the parser will often tell you which line the error appears on. 
This is part of the reason I use the <pre> tags.

I hope some of this will translate to PGSQL.

James Keeline

Reply via email to