pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Papp, Gyozo <pgerzson@freestart.hu>
To: Hillensbeck, Preston <PHillensbeck@sfbcic.com>
To: pgsql-php@postgresql.org
Subject: Re: what to do if a query fails
Date: Thu, 18 Apr 2002 10:25:33 +0200
Message-ID: <00e901c1e6b5$dc7e0540$01fdfea9@jaguar> (raw)
References: <040AE3A029B3D51181D000508BC75D0201387762@MERCURY>

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)




Message-ID: <00e901c1e6b5$dc7e0540$01fdfea9@jaguar>
Permalink:  ../00e901c1e6b5$dc7e0540$01fdfea9@jaguar/
Also on:    postgresql.org/message-id/00e901c1e6b5$dc7e0540$01fdfea9@jaguar

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: pgerzson@freestart.hu, PHillensbeck@sfbcic.com
  Subject: Re: what to do if a query fails
  In-Reply-To: <00e901c1e6b5$dc7e0540$01fdfea9@jaguar>
  References: <040AE3A029B3D51181D000508BC75D0201387762@MERCURY> <00e901c1e6b5$dc7e0540$01fdfea9@jaguar>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox