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 :

<?php
$id =3D $_POST['id'];
$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:<P> -
$titulo<BR>- $texto<BR>");
pg_close($db);
?>

This is a snip from modificar_1.php

<?php
$id =3D $_POST['id'];
$titulo =3D $_POST['titulo'];
$texto =3D $_POST['texto'];
=09
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;
?>
<table border=3D0 style=3D"border: 1px solid black;">
<?php
do {
$myrow =3D pg_fetch_row ($result, $row);
//print_r($myrow);
print ("<tr><td>ID</td><td>$myrow[0]</td></tr>");
print ("<tr><td>T=EDtulo</td><td><input type=3Dtext
value=3D$myrow[1] name=3Dtitulo size=3D150
maxlength=3D150></td></tr>");
print ("<tr><td>Texto</td><td><textarea cols=3D90
rows=3D20 value=3D$myrow[2]
name=3Dtexto>$myrow[2]</textarea></td></tr>");
$row++;
}
while ($row < $numrows);
?>

Thanks in advance


=3D=3D=3D=3D=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 [at] 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 imagen=
s!
http://www.cade.com.br

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

http://archives.postgresql.org
angelo_rigo [ Do, 14 August 2003 15:46 ] [ ID #46508 ]

Re: Update script

----- Original Message -----
From: "=C2ngelo Marcos Rigo" <angelo_rigo [at] yahoo.com.br>
To: <pgsql-php [at] postgresql.org>
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 :
>
> <?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=3D=3D0] 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:<P> -
> $titulo<BR>- $texto<BR>");
> pg_close($db);
> ?>
>
> This is a snip from modificar_1.php
>
> <?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;
> ?>
> <table border=3D0 style=3D"border: 1px solid black;">
> <?php
> do {
> $myrow =3D pg_fetch_row ($result, $row);
> //print_r($myrow);
> print ("<tr><td>ID</td><td>$myrow[0]</td></tr>");
> print ("<tr><td>T=EDtulo</td><td><input type=3Dtext
> value=3D$myrow[1] name=3Dtitulo size=3D150
> maxlength=3D150></td></tr>");
> print ("<tr><td>Texto</td><td><textarea cols=3D90
> rows=3D20 value=3D$myrow[2]
> name=3Dtexto>$myrow[2]</textarea></td></tr>");
> $row++;
> }
> while ($row < $numrows);
> ?>
>
> Thanks in advance
>
>
> =3D=3D=3D=3D=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 [at] 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 [at] postgresql.org)
Viorel Dragomir [ Do, 14 August 2003 15:57 ] [ ID #46509 ]

Re: Update script

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


>
> > 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 :
> >
> > <?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 is
> no id=3D=3D0] 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:<P> -
> > $titulo<BR>- $texto<BR>");
> > pg_close($db);
> > ?>
> >
> > This is a snip from modificar_1.php
> >
> > <?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;
> > ?>
> > <table border=3D0 style=3D"border: 1px solid black;">
> > <?php
> > do {
> > $myrow =3D pg_fetch_row ($result, $row);
> > //print_r($myrow);
> > print ("<tr><td>ID</td><td>$myrow[0]</td></tr>");
> > print ("<tr><td>T=EDtulo</td><td><input type=3Dtext
> > value=3D$myrow[1] name=3Dtitulo size=3D150
> > maxlength=3D150></td></tr>");
> > print ("<tr><td>Texto</td><td><textarea cols=3D90
> > rows=3D20 value=3D$myrow[2]
> > name=3Dtexto>$myrow[2]</textarea></td></tr>");
> > $row++;
> > }
> > while ($row < $numrows);
> > ?>
> >
> > Thanks in advance
> >
> >
> > =3D=3D=3D=3D=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 [at] 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
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the
> unregister command
> (send "unregister YourEmailAddressHere" to
majordomo [at] postgresql.org)

=3D=3D=3D=3D=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 [at] 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 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
angelo_rigo [ Do, 14 August 2003 18:55 ] [ ID #46511 ]

Re: Update script

Hi,


=C2ngelo Marcos Rigo wrote, On 8/14/2003 3:46 PM:
> 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 :
>
> <?php
> $id =3D $_POST['id'];
> $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'";
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
integer type. cast $id as integer, '".($id+0)."' or intval or others.

C.


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
CoL [ Fr, 15 August 2003 01:22 ] [ ID #46512 ]

Re: Update script

Hi Col

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

Best regards


--- CoL <col [at] mportal.hu> escreveu: > Hi,
>
>
> =C2ngelo Marcos Rigo wrote, On 8/14/2003 3:46 PM:
> > 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 :
> >
> > <?php
> > $id =3D $_POST['id'];
> > $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'";
> 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
> integer type. cast $id as integer, '".($id+0)."' or
> intval or others.
>
> C.
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

=3D=3D=3D=3D=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 [at] 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 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
angelo_rigo [ Fr, 15 August 2003 12:53 ] [ ID #46513 ]
Datenbanken » gmane.comp.db.postgresql.php » Update script

Vorheriges Thema: PHP and COPY
Nächstes Thema: Paging results