Re: PHP and PostgreSQL
| From: | Michael Teter | Date: | Wed, 05 Jul 2000 14:34:18 +0000 |
| Subject: | Re: PHP and PostgreSQL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-4951@lists.php.net to get a copy of this message | ||
There must be a problem with your code. Here's a page of mine that works fine (inserting NULLs
for fields that the user didn't touch.) Remember though, I _should_ be checking quality of data
before I insert... I just haven't done this part yet.
I have a form called addPerson.html that has a bunch of text fields. The submit calls this page
below (addPerson.php.)
if all this doesn't clear it up for you, email me your code and I'll look at it.
(michael_teter@yahoo.com)
----------------------------code sample------------------------------Error: failed to connect to
database.";}if ($bResult == TRUE) { $result = pg_exec($dbConn, $strSQL); if (!$result) {
$bResult = FALSE; $msg .= "
Error: failed to Add Person."; } else { $oid = pg_GetLastOid($result); if ($oid
Warning: OID Warning: Unable to get generated ID for person."; } else { $arr =
pg_fetch_array($result, 0); $idperson = $arr[0]; } } }}?>Add Person ResultsAdd
Person Results
-1) { echo("Generated ID for the person is: $idperson
");}if ($bResult == TRUE) { echo("Success!
");}else { echo("Failure!
");}echo("$msg
");?>----------------------------end code sample------------------------------
------------------------------------
--- Corey Mosher <corey@hub.org> wrote:
> Michael,
> I know this will work, working directly in the
> database,
> I've tested it extensively. My problem is that when
> you
> do the insert through a PHP script, it doesn't work,
> spaces
> are inserted no matter what you do.
>
> Corey
>
> On Tue, 4 Jul 2000, Michael Teter wrote:
>
> > Ok I just tested this:
> >
> > "insert into tableBlah (name, review) values
> > ('me',NULL)"
> >
> > That does insert a NULL for review.
> >
> > Then I do this:
> >
> > "select * from tableBlah where review is NULL"
> >
> > I get:
> >
> > name | review
> > ------+---------
> > me |
> >
> > So inserting the NULL does work. You just need to
> > programmatically build your insert statement such
> that
> > you put "NULL" where review goes, or "'the review
> > string'" if there's a real value.
> >
> > michael
> >
> >
> > --- Corey Mosher <corey@hub.org> wrote:
> > > Michael,
> > >
> > > This does not work for me, I have tried it
> already.
> > >
> > > Corey
> > >
> > > On Tue, 4 Jul 2000, Michael Teter wrote:
> > >
> > > > "insert into someTable (someColumn) values
> (NULL)"
> > > >
> > > > or
> > > >
> > > > $someVar = "NULL"
> > > > "insert into someTable(someColumn) values
> > > ($someVar)"
> > > >
> > > > or if you're not sure if someVar will have a
> real
> > > > value or instead a null value, do this:
> > > >
> > > > ...test $someVar... is it null or all space?
> > > > yes: $someVar = "NULL"
> > > > no: $someVar = "'" . $someVar . "'"
> > > >
> > > > then do this again:
> > > > "insert into someTable(someColumn) values
> > > ($someVar)"
> > > >
> > > > michael
> > > >
> > > > --- Corey Mosher <corey@hub.org> wrote:
> > > > > Hi,
> > > > > I am trying to do an insert into my
> > > postgreSQL
> > > > > database
> > > > > from a form. When I try to insert a null
> value,
> > > it
> > > > > gets
> > > > > put into the database as a string of spaces.
>
> > > Any
> > > > > ideas as to
> > > > > why and how to insert the correct null
> value?
> > > > >
> > > > > Corey Mosher
> > > > > Hub.Org Networking Services
> > > > > Wolfville, NS
> > > > > Canada
> > > > > corey@hub.org
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > PHP General Mailing List
> (http://www.php.net/)
> > > > > To unsubscribe, e-mail:
> > > > > php-general-unsubscribe@lists.php.net
> > > > > For additional commands, e-mail:
> > > > > php-general-help@lists.php.net
> > > > > To contact the list administrators, e-mail:
> > > > > php-list-admin@lists.php.net
> > > > >
> > > >
> > > >
> > > >
> __________________________________________________
> > > > Do You Yahoo!?
> > > > Kick off your party with Yahoo! Invites.
> > > > http://invites.yahoo.com/
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, e-mail:
> > > php-general-unsubscribe@lists.php.net
> > > > For additional commands, e-mail:
> > > php-general-help@lists.php.net
> > > > To contact the list administrators, e-mail:
> > > php-list-admin@lists.php.net
> > > >
> > >
> > > Corey Mosher
> > > Hub.Org Networking Services
> > > Wolfville, NS
> > > Canada
> > > corey@hub.org
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail:
> > > php-general-unsubscribe@lists.php.net
> > > For additional commands, e-mail:
> > > php-general-help@lists.php.net
> > > To contact the list administrators, e-mail:
> > > php-list-admin@lists.php.net
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Kick off your party with Yahoo! Invites.
> > http://invites.yahoo.com/
> >
>
> Corey Mosher
> Hub.Org Networking Services
> Wolfville, NS
> Canada
> corey@hub.org
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail:
> php-general-unsubscribe@lists.php.net
> For additional commands, e-mail:
> php-general-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>
---------------------------------
Do You Yahoo!?
Kick off your party with Yahoo! Invites.