Update script

Update script

am 14.08.2003 15:46:46 von angelo_rigo

Hi=20

I have a script to update some records in a postgresql
database. when i do modify what i have to modify it
give me the warning:=20

Warning: pg_query() query failed: ERROR: pg_atoi:
zero-length string in
/var/www/html/adm/modificar_2.php on line 24
ERROR

this is line 24:
$result =3D pg_query($db, $query);

this is modificar_2.php :

$id =3D $_POST['id'];
$titulo =3D $_POST['titulo'];
$texto =3D $_POST['texto'];

include 'db.php';=20
$query =3D "UPDATE table SET titulo=3D'$titulo',
texto=3D'$texto' WHERE id=3D'$id'";
$result =3D pg_query($db, $query);
if (!$result) {printf ("ERROR"); exit;}
print ("Estes valores foram atualizados:

-
$titulo
- $texto
");
pg_close($db);
?>

This is a snip from modificar_1.php

$id =3D $_POST['id'];
$titulo =3D $_POST['titulo'];
$texto =3D $_POST['texto'];
=09
include 'db.php';=20
$query =3D "SELECT id, titulo, texto FROM table WHERE
id=3D'$id'";
$result =3D pg_exec($db, $query);
if (!$result) {printf ("ERROR"); exit;}
$numrows =3D pg_numrows($result);
$row=3D0;
?>


do {
$myrow =3D pg_fetch_row ($result, $row);
//print_r($myrow);
print ("");
print ("");
print ("");
$row++;
}
while ($row < $numrows);
?>

Thanks in advance


=====3D
=C2ngelo Marcos Rigo
AMR Inform=E1tica=20
(51) 3348 0870=20
Rua Pe. Alois Kades 400/210=20
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br
=20


____________________________________________________________ ___________
Conhe=E7a o novo Cad=EA? - Mais r=E1pido, mais f=E1cil e mais preciso.
Toda a web, 42 milh=F5es de p=E1ginas brasileiras e nova busca por imagen=
s!
http://www.cade.com.br

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Re: Update script

am 14.08.2003 15:57:41 von Viorel Dragomir

----- Original Message -----
From: "=C2ngelo Marcos Rigo"
To:
Sent: Thursday, August 14, 2003 4:46 PM
Subject: [PHP] Update script


> Hi
>
> I have a script to update some records in a postgresql
> database. when i do modify what i have to modify it
> give me the warning:
>
> Warning: pg_query() query failed: ERROR: pg_atoi:
> zero-length string in
> /var/www/html/adm/modificar_2.php on line 24
> ERROR
>
> this is line 24:
> $result =3D pg_query($db, $query);
>
> this is modificar_2.php :
>
> > $id =3D $_POST['id'];

Since this is the only thing that match an integer value, try to use
$id =3D $_POST['id'] + 0;
in case there is no id sent. You'll don't get any results [i hope there i=
s
no id==0] but u'll don't have an error on your query.
Because id is integer try not to use *where id=3D'$id'*. Use *where id=3D=
$id*
instead.

> $titulo =3D $_POST['titulo'];
> $texto =3D $_POST['texto'];
>
> include 'db.php';
> $query =3D "UPDATE table SET titulo=3D'$titulo',
> texto=3D'$texto' WHERE id=3D'$id'";
> $result =3D pg_query($db, $query);
> if (!$result) {printf ("ERROR"); exit;}
> print ("Estes valores foram atualizados:

-
> $titulo
- $texto
");
> pg_close($db);
> ?>
>
> This is a snip from modificar_1.php
>
> > $id =3D $_POST['id'];
> $titulo =3D $_POST['titulo'];
> $texto =3D $_POST['texto'];
>
> include 'db.php';
> $query =3D "SELECT id, titulo, texto FROM table WHERE
> id=3D'$id'";
> $result =3D pg_exec($db, $query);
> if (!$result) {printf ("ERROR"); exit;}
> $numrows =3D pg_numrows($result);
> $row=3D0;
> ?>
>

ID$myrow[0]
T=EDtulo value=3D$myrow[1] name=3Dtitulo size=3D150
maxlength=3D150>
Texto

> > do {
> $myrow =3D pg_fetch_row ($result, $row);
> //print_r($myrow);
> print ("");
> print ("");
> print ("");
> $row++;
> }
> while ($row < $numrows);
> ?>
>
> Thanks in advance
>
>
> =====3D
> =C2ngelo Marcos Rigo
> AMR Inform=E1tica
> (51) 3348 0870
> Rua Pe. Alois Kades 400/210
> Porto Alegre /RS/Brasil
> http://amr.freezope.org
> angelo_rigo@yahoo.com.br
>
>
>
> ____________________________________________________________ ___________
> Conhe=E7a o novo Cad=EA? - Mais r=E1pido, mais f=E1cil e mais preciso.
> Toda a web, 42 milh=F5es de p=E1ginas brasileiras e nova busca por imag=
ens!
> http://www.cade.com.br
>
> ---------------------------(end of broadcast)--------------------------=
-
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: Update script

am 14.08.2003 18:55:20 von angelo_rigo

It work in half :
I get the message that the values where updated but
the values are not really updated=20


>=20
> > Hi
> >
> > I have a script to update some records in a
> postgresql
> > database. when i do modify what i have to modify
> it
> > give me the warning:
> >
> > Warning: pg_query() query failed: ERROR: pg_atoi:
> > zero-length string in
> > /var/www/html/adm/modificar_2.php on line 24
> > ERROR
> >
> > this is line 24:
> > $result =3D pg_query($db, $query);
> >
> > this is modificar_2.php :
> >
> > > > $id =3D $_POST['id'];
>=20
> Since this is the only thing that match an integer
> value, try to use
> $id =3D $_POST['id'] + 0;
> in case there is no id sent. You'll don't get any
> results [i hope there is
> no id==0] but u'll don't have an error on your
> query.
> Because id is integer try not to use *where
> id=3D'$id'*. Use *where id=3D$id*
> instead.
>=20
> > $titulo =3D $_POST['titulo'];
> > $texto =3D $_POST['texto'];
> >
> > include 'db.php';
> > $query =3D "UPDATE table SET titulo=3D'$titulo',
> > texto=3D'$texto' WHERE id=3D'$id'";
> > $result =3D pg_query($db, $query);
> > if (!$result) {printf ("ERROR"); exit;}
> > print ("Estes valores foram atualizados:

-
> > $titulo
- $texto
");
> > pg_close($db);
> > ?>
> >
> > This is a snip from modificar_1.php
> >
> > > > $id =3D $_POST['id'];
> > $titulo =3D $_POST['titulo'];
> > $texto =3D $_POST['texto'];
> >
> > include 'db.php';
> > $query =3D "SELECT id, titulo, texto FROM table
> WHERE
> > id=3D'$id'";
> > $result =3D pg_exec($db, $query);
> > if (!$result) {printf ("ERROR"); exit;}
> > $numrows =3D pg_numrows($result);
> > $row=3D0;
> > ?>
> >

ID$myrow[0]
T=EDtulo > value=3D$myrow[1] name=3Dtitulo size=3D150
> maxlength=3D150>
Texto

> > > > do {
> > $myrow =3D pg_fetch_row ($result, $row);
> > //print_r($myrow);
> > print ("");
> > print ("");
> > print ("");
> > $row++;
> > }
> > while ($row < $numrows);
> > ?>
> >
> > Thanks in advance
> >
> >
> > =====3D
> > =C2ngelo Marcos Rigo
> > AMR Inform=E1tica
> > (51) 3348 0870
> > Rua Pe. Alois Kades 400/210
> > Porto Alegre /RS/Brasil
> > http://amr.freezope.org
> > angelo_rigo@yahoo.com.br
> >
> >
> >
> >
>
____________________________________________________________ ___________
> > Conhe=E7a o novo Cad=EA? - Mais r=E1pido, mais f=E1cil e
> mais preciso.
> > Toda a web, 42 milh=F5es de p=E1ginas brasileiras e
> nova busca por imagens!
> > http://www.cade.com.br
> >
> > ---------------------------(end of
> broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
>=20
>=20
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the
> unregister command
> (send "unregister YourEmailAddressHere" to
majordomo@postgresql.org)=20

=====3D
=C2ngelo Marcos Rigo
AMR Inform=E1tica=20
(51) 3348 0870=20
Rua Pe. Alois Kades 400/210=20
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br
=20


____________________________________________________________ ___________
Conhe=E7a o novo Cad=EA? - Mais r=E1pido, mais f=E1cil e mais preciso.
Toda a web, 42 milh=F5es de p=E1ginas brasileiras e nova busca por imagen=
s!
http://www.cade.com.br

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Re: Update script

am 15.08.2003 01:22:32 von CoL

Hi,


=C2ngelo Marcos Rigo wrote, On 8/14/2003 3:46 PM:
> Hi=20
>=20
> I have a script to update some records in a postgresql
> database. when i do modify what i have to modify it
> give me the warning:=20
>=20
> Warning: pg_query() query failed: ERROR: pg_atoi:
> zero-length string in
> /var/www/html/adm/modificar_2.php on line 24
> ERROR
>=20
> this is line 24:
> $result =3D pg_query($db, $query);
>=20
> this is modificar_2.php :
>=20
> > $id =3D $_POST['id'];
> $titulo =3D $_POST['titulo'];
> $texto =3D $_POST['texto'];
>=20
> include 'db.php';=20
> $query =3D "UPDATE table SET titulo=3D'$titulo',
> texto=3D'$texto' WHERE id=3D'$id'";
print $query; You will get:
UPDATE table SET titulo=3D'somthing',texto=3D'text' WHERE id=3D''

And your pg version is >=3D 7.2, where you can not insert '' string in=20
integer type. cast $id as integer, '".($id+0)."' or intval or others.

C.


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Re: Update script

am 15.08.2003 12:53:52 von angelo_rigo

Hi Col=20

Thank=B4s for the postgre version note=20
my problem was that i just forget the name=3Did atribute
in the textfield=20

Best regards


--- CoL escreveu: > Hi,
>=20
>=20
> =C2ngelo Marcos Rigo wrote, On 8/14/2003 3:46 PM:
> > Hi=20
> >=20
> > I have a script to update some records in a
> postgresql
> > database. when i do modify what i have to modify
> it
> > give me the warning:=20
> >=20
> > Warning: pg_query() query failed: ERROR: pg_atoi:
> > zero-length string in
> > /var/www/html/adm/modificar_2.php on line 24
> > ERROR
> >=20
> > this is line 24:
> > $result =3D pg_query($db, $query);
> >=20
> > this is modificar_2.php :
> >=20
> > > > $id =3D $_POST['id'];
> > $titulo =3D $_POST['titulo'];
> > $texto =3D $_POST['texto'];
> >=20
> > include 'db.php';=20
> > $query =3D "UPDATE table SET titulo=3D'$titulo',
> > texto=3D'$texto' WHERE id=3D'$id'";
> print $query; You will get:
> UPDATE table SET titulo=3D'somthing',texto=3D'text'
> WHERE id=3D''
>=20
> And your pg version is >=3D 7.2, where you can not
> insert '' string in=20
> integer type. cast $id as integer, '".($id+0)."' or
> intval or others.
>=20
> C.
>=20
>=20
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster=20

=====3D
=C2ngelo Marcos Rigo
AMR Inform=E1tica=20
(51) 3348 0870=20
Rua Pe. Alois Kades 400/210=20
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br
=20


____________________________________________________________ ___________
Conhe=E7a o novo Cad=EA? - Mais r=E1pido, mais f=E1cil e mais preciso.
Toda a web, 42 milh=F5es de p=E1ginas brasileiras e nova busca por imagen=
s!
http://www.cade.com.br

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

ID$myrow[0]
T=EDtulo > > value=3D$myrow[1] name=3Dtitulo size=3D150
> > maxlength=3D150>
Texto