Обсуждение: PostgreSQL - PHP insert deleted from database immediately?

Поиск
Список
Период
Сортировка

PostgreSQL - PHP insert deleted from database immediately?

От
"Sami"
Дата:
Hi, I'm trying to insert data from a php-page. The connection is open and
select-functions work perfectly. The problem is that an insert will - as far
as I know - insert the data and then immediately erase it.

The insert statement executed from php is:

     $otsikko = "Insert testi";
     $teksti = "Koeteksti 1";

     $sqllause = "INSERT INTO jutut (otsikko,teksti) VALUES ('";
     $sqllause = $sqllause . $otsikko . "','" . $teksti . "');";
     ECHO $sqllause;
     $tulos = pg_exec ($db,$sqllause);
     if (!$tulos) {
        echo "Sql-insert error.\n";
        exit;
     }
This results are the following in the web-browser:

    INSERT INTO jutut (otsikko,teksti) VALUES ('Insert testi','Koeteksti
1');

Which when copied into the psql-console  indeed does the insert correctly.

The reason I know the PHP-insert is done, but deleted is derived from the
fact that an automatically incremented index in the table is incremented
when the php-script is executed.

 I get no error messages.

Could someone please help?



Re: PostgreSQL - PHP insert deleted from database immediately?

От
Ricardo Campos Passanezi
Дата:
...
> The insert statement executed from php is:
>
>      $otsikko = "Insert testi";
>      $teksti = "Koeteksti 1";
>
>      $sqllause = "INSERT INTO jutut (otsikko,teksti) VALUES ('";
>      $sqllause = $sqllause . $otsikko . "','" . $teksti . "');";

Have you tried without the ";"? Just like:

$sqllause = "INSERT INTO jutut (otsikko,teksti) VALUES ('";
$sqllause = $sqllause . $otsikko . "','" . $teksti . "')";


I have similar stuff around here, and it works just fine.

The piece of code I have:

$connect = pg_connect("host=$host dbname=$db user=$user password=$pass");
$insert_query = "INSERT INTO table(field1,field2,...,fieldN)
VALUES('$field1','$field2',...,'$fieldN')";

$result = pg_exec($connect,$insert_query);

pg_close($connect);

Obs: the $insert_query is defined in one line...

Ricardo.


Re: PostgreSQL - PHP insert deleted from database immediately?

От
"Sami"
Дата:
 > The insert statement executed from php is:
> >
> >      $otsikko = "Insert testi";
> >      $teksti = "Koeteksti 1";
> >
> >      $sqllause = "INSERT INTO jutut (otsikko,teksti) VALUES ('";
> >      $sqllause = $sqllause . $otsikko . "','" . $teksti . "');";
>
> Have you tried without the ";"? Just like:
>
> $sqllause = "INSERT INTO jutut (otsikko,teksti) VALUES ('";
> $sqllause = $sqllause . $otsikko . "','" . $teksti . "')";

Yes, tried it, didn't work.
Still at a loss as to what the problem is.
I haven't even had the time to figure out a workaround if there is any as
the problem is a pretty basic one.

Could it possibly be a problem with the database configuration?





Re: Re: PostgreSQL - PHP insert deleted from database immediately?

От
"John Clark L. Naldoza"
Дата:
Sami wrote:
>
>  > The insert statement executed from php is:
> > >
> > >      $otsikko = "Insert testi";
> > >      $teksti = "Koeteksti 1";
> > >
> > >      $sqllause = "INSERT INTO jutut (otsikko,teksti) VALUES ('";
> > >      $sqllause = $sqllause . $otsikko . "','" . $teksti . "');";

Hmmm....  Looks a bit wierd..;-(

$sqllause = "INSERT INTO jutut (otsikko,teksti) VALUES
('$otsikko','$teksti');";

Should work...;-)

How did you execute the SQL query with PHP?
> >
> > Have you tried without the ";"? Just like:
> >
> > $sqllause = "INSERT INTO jutut (otsikko,teksti) VALUES ('";
> > $sqllause = $sqllause . $otsikko . "','" . $teksti . "')";
>
> Yes, tried it, didn't work.
> Still at a loss as to what the problem is.
> I haven't even had the time to figure out a workaround if there is any as
> the problem is a pretty basic one.
>
> Could it possibly be a problem with the database configuration?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--
     /) John Clark Naldoza y Lopez                           (\
    / )    Software Design Engineer II                       ( \
  _( (_    _  Web-Application Development                    _) )_
 (((\ \>  /_>    Cable Modem Network Management System <_\  </ /)))
 (\\\\ \_/ /         NEC Telecom Software Phils., Inc.  \ \_/ ////)
  \       /                                              \       /
   \    _/  phone: (+63 32) 233-9142 loc. 3112            \_    /
   /   /  cellphone: (+63 919) 399-4742                     \   \
  /   / email: njclark@ntsp.nec.co.jp                        \   \