Thread:
I am currently experiencing a problem passing data from a PHP page to PostgreSQL. I am passing different data types like numeric, and text. Let me show you some of the code I am using.... This is the code that I am using to pass the input data to a page called "checkbook2.php" <form action="checkbook2.php" method="GET"> <p align="center">Check Date <input type="text" name="check_date" VALUE=""> Check Number <input type="text" name="check_number" VALUE=""> Check Payee <input type="text" name="check_payee" VALUE=""> Check Amount <input type="text" name="check_amount" VALUE=""> </p> <p align="center">Check Transaction Type <input type="text" name="check_trans_type" VALUE=""> </p> <input type=submit value="Add New Entry"> </form> This is the data from the checkbook2.php that talks to the PostgreSQL Server. It is running version 7.2. $conn=pg_connect("host=192.168.0.2 user=postgres password=postgres dbname=checkbook"); @$sql="INSERT INTO checking VALUES('$check_date', '$check_num', '$check_pay', '$check_amount', '$check_trans_type');"; $result=pg_exec($conn, $sql); check_data is type text check_num is type int4 check_pay is type text check_amount is type numeric(8,2) check_trans_type is type text The error that comes up is ... Warning: PostgreSQL query failed: ERROR: Bad numeric input format 'check_trans_type' in /etc/httpd/htdocs/checkbook2.php on line 41 Anyone know what could be going on here?? Please let me know, thanks in advance! :)
Hi Preston @$sql="INSERT INTO checking VALUES('$check_date', '$check_num', '$check_pay', '$check_amount', '$check_trans_type');"; Try your INSERT without '' around '$check_amount'. The quotes are only used for character-types but not for numeric data. Regards Conni
Hmmm well it still tells me the same thing when I take the quotes off. Is there some type of casting that I might have to do? I have read about the cast command, but don't understand how to use it. -----Original Message----- From: Cornelia Boenigk [mailto:poppcorn@cornelia-boenigk.de] Sent: Wednesday, April 17, 2002 4:19 PM To: pgsql-php@postgresql.org Subject: Re: [PHP] Hi Preston @$sql="INSERT INTO checking VALUES('$check_date', '$check_num', '$check_pay', '$check_amount', '$check_trans_type');"; Try your INSERT without '' around '$check_amount'. The quotes are only used for character-types but not for numeric data. Regards Conni ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org
On Wed, 17 Apr 2002, Hillensbeck, Preston wrote: > <input type="text" name="check_trans_type" VALUE=""> > > @$sql="INSERT INTO checking VALUES('$check_date', '$check_num', > '$check_pay', '$check_amount', '$check_trans_type');"; > check_trans_type is type text > > The error that comes up is ... > Warning: PostgreSQL query failed: ERROR: Bad numeric input format > 'check_trans_type' in /etc/httpd/htdocs/checkbook2.php on line 41 > POST_VARS should always be strings. Have you tried this without the php, as in psql. What happens when you replace, in the insert statement, $check_trans_type, with a correct value? Is it supposed to be like withdrawl, deposit...etc? Good luck Chadwick Rolfs - cmr@gis.net Cleveland State University - Student Music Major - The Holden Arboretum Volunteer Computer Programmer - Student Employee --*I finally found powdered water; I just can't figure out what to add to it*--
Have you tried echoing the $sql after it is created? it's possible that you have nothing in your php variables. In that case, and empty string would cause and error. Otherwise, postgres doesn't care if you have quotes around an numeric type on insert. -Dan Quoting "Hillensbeck, Preston" <PHillensbeck@sfbcic.com>: > Hmmm well it still tells me the same thing when I take the quotes off. Is > there some type of casting that I might have to do? I have read about the > cast command, but don't understand how to use it. > > Hi Preston > > @$sql="INSERT INTO checking VALUES('$check_date', '$check_num', > '$check_pay', '$check_amount', '$check_trans_type');"; > > Try your INSERT without '' around '$check_amount'. The quotes are only > used for character-types but not for numeric data. > > Regards > Conni > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >
Ok I figured it out... I wasn't sending data to all of the columns, just some. I had some other columns called check_pre_balance and check_post_balance. When I entered data for those columns it went through. The reason I didn't enter data for those columns is because I haven't worked on the SQL command to update the pre and post balances yet and was doing some testing first. Ok, well thanks for the replies everyone :) > <input type="text" name="check_trans_type" VALUE=""> > > @$sql="INSERT INTO checking VALUES('$check_date', '$check_num', > '$check_pay', '$check_amount', '$check_trans_type');"; > check_trans_type is type text > > The error that comes up is ... > Warning: PostgreSQL query failed: ERROR: Bad numeric input format > 'check_trans_type' in /etc/httpd/htdocs/checkbook2.php on line 41 > POST_VARS should always be strings. Have you tried this without the php, as in psql. What happens when you replace, in the insert statement, $check_trans_type, with a correct value? Is it supposed to be like withdrawl, deposit...etc? Good luck Chadwick Rolfs - cmr@gis.net Cleveland State University - Student Music Major - The Holden Arboretum Volunteer Computer Programmer - Student Employee --*I finally found powdered water; I just can't figure out what to add to it*--
* Hillensbeck, Preston <PHillensbeck@sfbcic.com> [17 04 02 23:30]: >Hmmm well it still tells me the same thing when I take the quotes off. Is >there some type of casting that I might have to do? I have read about the >cast command, but don't understand how to use it. Looks like the definition of the attribut check_trans_type is not text, but numeric. The quotes are not needed when entering numeric data but they also do not disturb. > > >Hi Preston > >@$sql="INSERT INTO checking VALUES('$check_date', '$check_num', >'$check_pay', '$check_amount', '$check_trans_type');"; > >Try your INSERT without '' around '$check_amount'. The quotes are only >used for character-types but not for numeric data. > -- --//--\\-- Eckhard Hoeffner e-hoeffner@fifoost.org Tal 44 D-80331 München
You can also use insert into checking (<whatever columns here>) values ('whatever', 'values', 'here'); That's what I do... On Wed, 17 Apr 2002, Hillensbeck, Preston wrote: > Ok I figured it out... I wasn't sending data to all of the columns, just > some. I had some other columns called check_pre_balance and > check_post_balance. When I entered data for those columns it went through. > The reason I didn't enter data for those columns is because I haven't worked > on the SQL command to update the pre and post balances yet and was doing > some testing first. Ok, well thanks for the replies everyone :) > > > > <input type="text" name="check_trans_type" VALUE=""> > > > > > @$sql="INSERT INTO checking VALUES('$check_date', '$check_num', > > '$check_pay', '$check_amount', '$check_trans_type');"; > > > check_trans_type is type text > > > > The error that comes up is ... > > Warning: PostgreSQL query failed: ERROR: Bad numeric input format > > 'check_trans_type' in /etc/httpd/htdocs/checkbook2.php on line 41 > > > > POST_VARS should always be strings. Have you tried this without the php, > as in psql. What happens when you replace, in the insert statement, > $check_trans_type, with a correct value? Is it supposed to be like > withdrawl, deposit...etc? > Good luck > Chadwick Rolfs - cmr@gis.net Cleveland State University - Student Music Major - The Holden Arboretum Volunteer Computer Programmer - Student Employee --*I finally found powdered water; I just can't figure out what to add to it*--
Hi, I summarized what to do if a query fails. It's advisable to: + var_dump() all variables ($connection, $query and all used in $query) + log your queries to see what postgres tries to do + check the table definition + use explicit column list in INSERT (even so, future pg release may not support abbreviated INSERT syntax) and some additional notes not related to the original topic: | $conn=pg_connect("host=192.168.0.2 user=postgres password=postgres | dbname=checkbook"); + do not connect in to postgres as superuser! + escape and quote all user input sent to database backend! (consider using addslashes(), sprintf(), etc.) For detailed information visit: http://www.php.net/manual/en/security.database.php ----- Original Message ----- From: "Hillensbeck, Preston" <PHillensbeck@sfbcic.com> To: <pgsql-php@postgresql.org> Sent: Wednesday, April 17, 2002 11:03 PM Subject: [PHP] | I am currently experiencing a problem passing data from a PHP page to | PostgreSQL. | | I am passing different data types like numeric, and text. Let me show you | some of the code I am using.... | | This is the code that I am using to pass the input data to a page called | "checkbook2.php" | | <form action="checkbook2.php" method="GET"> | <p align="center">Check Date | <input type="text" name="check_date" VALUE=""> | Check Number | <input type="text" name="check_number" VALUE=""> | Check Payee | <input type="text" name="check_payee" VALUE=""> | Check Amount | <input type="text" name="check_amount" VALUE=""> | </p> | <p align="center">Check Transaction Type | <input type="text" name="check_trans_type" VALUE=""> | </p> | <input type=submit value="Add New Entry"> | </form> | | This is the data from the checkbook2.php that talks to the PostgreSQL | Server. It is running version 7.2. | | $conn=pg_connect("host=192.168.0.2 user=postgres password=postgres | dbname=checkbook"); | | @$sql="INSERT INTO checking VALUES('$check_date', '$check_num', | '$check_pay', '$check_amount', '$check_trans_type');"; | | $result=pg_exec($conn, $sql); | | check_data is type text | check_num is type int4 | check_pay is type text | check_amount is type numeric(8,2) | check_trans_type is type text | | The error that comes up is ... | Warning: PostgreSQL query failed: ERROR: Bad numeric input format | 'check_trans_type' in /etc/httpd/htdocs/checkbook2.php on line 41 | | Anyone know what could be going on here?? Please let me know, thanks in | advance! :) | | | | ---------------------------(end of broadcast)--------------------------- | TIP 2: you can get off all lists at once with the unregister command | (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)