Re: empty form fields, NULLS, quoting, postgreSQL inserts into

Поиск
Список
Период
Сортировка
От Vince Vielhaber
Тема Re: empty form fields, NULLS, quoting, postgreSQL inserts into
Дата
Msg-id Pine.BSF.4.44.0303281217380.34973-100000@paprika.michvhf.com
обсуждение исходный текст
Ответ на empty form fields, NULLS, quoting, postgreSQL inserts into date, interval fields...  (Dan Jewett <danjewett@mac.com>)
Список pgsql-php
On Fri, 28 Mar 2003, Dan Jewett wrote:

> I'm having trouble getting NULLs into date/time fields and interval
> fields.
>
> I've gotten this far:
>
> $trk_length = $_POST['trk_length'];
> if (empty($trk_length))                    //or if($trk_length == '')
>     $trk_length = NULL;
>
> or
>
> $length_str = $_POST['trk_length'];
>     if (empty($length_str))
>         $trk_length = NULL;
>     else $trk_length = $length_str;
>
> The insert:
>
> $result = pg_query($conn, "INSERT INTO track (field1, field2,
> trk_length) VALUES ('$var1', '$var2', '$trk_length')");
>
> This results in a "bad external representation ''." error for the
> insert.  If I use double quotes, ie. $trk_length = "NULL"; and remove
> the single quotes from the $trk_length variable in the insert
> statement, the insert succeeds.  But now, if $trk_length is not empty,
> the insert fails with a parse error on the : character in my interval
> string.

embed the single quotes into $trk_length.

if(empty($trk_length))
    $tkln = "NULL";
else
    $tkln = "'$trk_length'";

... VALUES ('$var1', '$var2', $tkln)");

Vince.
--
 Fast, inexpensive internet service 56k and beyond!  http://www.pop4.net/
   http://www.meanstreamradio.com       http://www.unknown-artists.com
         Internet radio: It's not file sharing, it's just radio.


В списке pgsql-php по дате отправления:

Предыдущее
От: Dan Jewett
Дата:
Сообщение: empty form fields, NULLS, quoting, postgreSQL inserts into date, interval fields...
Следующее
От: Rod Kreisler
Дата:
Сообщение: Re: empty form fields, NULLS, quoting, postgreSQL