Forum Moderators: coopster

Message Too Old, No Replies

postgresql/php insert problem

         

denzity

10:55 pm on May 18, 2004 (gmt 0)

10+ Year Member



Hi, I,m using postgresql and keep getting this error during an insert query.

query failed: ERROR: pg_atoi: zero-length string in...

this is because the variable contains no value nothing so I'm trying to assign a null value if the variable is empty...

if (empty($Memory)) { $Memory=NULL;} 


apparently postgresql will accept a null value but not nothing. However it is not accepting null either as I get the same error before and after assigning null to the variable.

Bob

coopster

11:18 pm on May 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



PHP is assigning your
$Memory
variable the value of
NULL
. If you print it out, nothing will be displayed or printed to output, just the null value. Try running your INSERT with the actual word NULL, not the value null.
if (empty($Memory)) { $Memory='NULL';}
Note the single quotation marks, now assigning the word NULL to your variable as opposed to the value.

denzity

11:36 pm on May 18, 2004 (gmt 0)

10+ Year Member



tried that

if (empty($Memory)) {$Memory='NULL';} 

and got this error

query failed: ERROR: pg_atoi: error in "NULL": can't parse "NULL" in...

thanks for the reply

coopster

11:44 pm on May 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Can you show us the INSERT syntax?

denzity

12:22 am on May 19, 2004 (gmt 0)

10+ Year Member



$INSquery= "INSERT INTO \"tblWorkstation\" Values (
'{$WSID}',
'{$Make}',
'{$WSModelName}',
'{$WSModelNum}',
'{$Serial}',
'{$CPU}',
'{$HDD}',
'{$FDD}',
'{$Memory}',
'{$MacAdd}',
'{$NIC}',
'{$IPAdd}',
'{$RCCode}',
'{$OSName}',
'{$DatPurch}',
'{$Replaced}',
'{$PCordLen}',
'{$AssetID}',
'{$DatInst}',
'{$DatEnt}',
'{$TName}',
'{$Comments}',
'{$DeptName}',
'{$BuildName}',
'{$Level}',
'{$ComUser}',
'{$Outlet}',
'{$Situation}')";

coopster

1:08 pm on May 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Your problem still lies in the INSERT statement, right here...
$INSquery= "INSERT INTO \"tblWorkstation\" Values ( 
...
'{$Memory}',
...
'{$ComUser}',
'{$Outlet}',
'{$Situation}')";
...specifically in that you are enclosing the value in quotation marks, which postgresql is choking on.

This thread [webmasterworld.com] addresses a similar issue, how to insert a NULL value, except for MySQL. However, the same syntax holds true for postgresql. Note particularly message number 17.

[edited by: jatar_k at 4:02 pm (utc) on May 19, 2004]