pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Update script
6+ messages / 4 participants
[nested] [flat]

* Update script
@ 2003-08-14 13:46  Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
  0 siblings, 3 replies; 6+ messages in thread

From: Ângelo Marcos Rigo @ 2003-08-14 13:46 UTC (permalink / raw)
  To: pgsql-php

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 = pg_query($db, $query);

this is modificar_2.php :

<?php
	$id = $_POST['id'];
	$titulo = $_POST['titulo'];
	$texto = $_POST['texto'];

	include 'db.php'; 
	$query = "UPDATE table SET titulo='$titulo',
texto='$texto' WHERE id='$id'";
	$result = 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 = $_POST['id'];
	$titulo = $_POST['titulo'];
	$texto = $_POST['texto'];
	
	include 'db.php'; 
	$query = "SELECT id, titulo, texto FROM table WHERE
id='$id'";
	$result = pg_exec($db, $query);
	if (!$result) {printf ("ERROR"); exit;}
	$numrows = pg_numrows($result);
	$row=0;
	?>
	<table border=0 style="border: 1px solid black;">
	<?php
		do {
		$myrow = pg_fetch_row ($result, $row);
		//print_r($myrow);
		print ("<tr><td>ID</td><td>$myrow[0]</td></tr>");
		print ("<tr><td>Título</td><td><input type=text
value=$myrow[1] name=titulo size=150
maxlength=150></td></tr>");
		print ("<tr><td>Texto</td><td><textarea cols=90
rows=20 value=$myrow[2]
name=texto>$myrow[2]</textarea></td></tr>");
		$row++;
	}
	while ($row < $numrows);
	?>

Thanks in advance


=====
Ângelo Marcos Rigo
AMR Informática 
(51) 3348 0870 
Rua Pe. Alois Kades 400/210 
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br
 


_______________________________________________________________________
Conheça o novo Cadê? - Mais rápido, mais fácil e mais preciso.
Toda a web, 42 milhões de páginas brasileiras e nova busca por imagens!
http://www.cade.com.br



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Update script
@ 2003-08-14 13:57  Viorel Dragomir <bc@vio.ro>
  parent: Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
  2 siblings, 1 reply; 6+ messages in thread

From: Viorel Dragomir @ 2003-08-14 13:57 UTC (permalink / raw)
  To: pgsql-php


----- Original Message -----
From: "Ângelo Marcos Rigo" <angelo_rigo@yahoo.com.br>
To: <pgsql-php@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 = pg_query($db, $query);
>
> this is modificar_2.php :
>
> <?php
> $id = $_POST['id'];

Since this is the only thing that match an integer value, try to use
$id = $_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='$id'*. Use *where id=$id*
instead.

> $titulo = $_POST['titulo'];
> $texto = $_POST['texto'];
>
> include 'db.php';
> $query = "UPDATE table SET titulo='$titulo',
> texto='$texto' WHERE id='$id'";
> $result = 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 = $_POST['id'];
> $titulo = $_POST['titulo'];
> $texto = $_POST['texto'];
>
> include 'db.php';
> $query = "SELECT id, titulo, texto FROM table WHERE
> id='$id'";
> $result = pg_exec($db, $query);
> if (!$result) {printf ("ERROR"); exit;}
> $numrows = pg_numrows($result);
> $row=0;
> ?>
> <table border=0 style="border: 1px solid black;">
> <?php
> do {
> $myrow = pg_fetch_row ($result, $row);
> //print_r($myrow);
> print ("<tr><td>ID</td><td>$myrow[0]</td></tr>");
> print ("<tr><td>Título</td><td><input type=text
> value=$myrow[1] name=titulo size=150
> maxlength=150></td></tr>");
> print ("<tr><td>Texto</td><td><textarea cols=90
> rows=20 value=$myrow[2]
> name=texto>$myrow[2]</textarea></td></tr>");
> $row++;
> }
> while ($row < $numrows);
> ?>
>
> Thanks in advance
>
>
> =====
> Ângelo Marcos Rigo
> AMR Informática
> (51) 3348 0870
> Rua Pe. Alois Kades 400/210
> Porto Alegre /RS/Brasil
> http://amr.freezope.org
> angelo_rigo@yahoo.com.br
>
>
>
> _______________________________________________________________________
> Conheça o novo Cadê? - Mais rápido, mais fácil e mais preciso.
> Toda a web, 42 milhões de páginas 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




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Update script
@ 2003-08-14 16:55  Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
  parent: Viorel Dragomir <bc@vio.ro>
  0 siblings, 0 replies; 6+ messages in thread

From: Ângelo Marcos Rigo @ 2003-08-14 16:55 UTC (permalink / raw)
  To: Viorel Dragomir <bc@vio.ro>; pgsql-php

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 = pg_query($db, $query);
> >
> > this is modificar_2.php :
> >
> > <?php
> > $id = $_POST['id'];
> 
> Since this is the only thing that match an integer
> value, try to use
> $id = $_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='$id'*. Use *where id=$id*
> instead.
> 
> > $titulo = $_POST['titulo'];
> > $texto = $_POST['texto'];
> >
> > include 'db.php';
> > $query = "UPDATE table SET titulo='$titulo',
> > texto='$texto' WHERE id='$id'";
> > $result = 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 = $_POST['id'];
> > $titulo = $_POST['titulo'];
> > $texto = $_POST['texto'];
> >
> > include 'db.php';
> > $query = "SELECT id, titulo, texto FROM table
> WHERE
> > id='$id'";
> > $result = pg_exec($db, $query);
> > if (!$result) {printf ("ERROR"); exit;}
> > $numrows = pg_numrows($result);
> > $row=0;
> > ?>
> > <table border=0 style="border: 1px solid black;">
> > <?php
> > do {
> > $myrow = pg_fetch_row ($result, $row);
> > //print_r($myrow);
> > print ("<tr><td>ID</td><td>$myrow[0]</td></tr>");
> > print ("<tr><td>Título</td><td><input type=text
> > value=$myrow[1] name=titulo size=150
> > maxlength=150></td></tr>");
> > print ("<tr><td>Texto</td><td><textarea cols=90
> > rows=20 value=$myrow[2]
> > name=texto>$myrow[2]</textarea></td></tr>");
> > $row++;
> > }
> > while ($row < $numrows);
> > ?>
> >
> > Thanks in advance
> >
> >
> > =====
> > Ângelo Marcos Rigo
> > AMR Informática
> > (51) 3348 0870
> > Rua Pe. Alois Kades 400/210
> > Porto Alegre /RS/Brasil
> > http://amr.freezope.org
> > angelo_rigo@yahoo.com.br
> >
> >
> >
> >
>
_______________________________________________________________________
> > Conheça o novo Cadê? - Mais rápido, mais fácil e
> mais preciso.
> > Toda a web, 42 milhões de páginas 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@postgresql.org) 

=====
Ângelo Marcos Rigo
AMR Informática 
(51) 3348 0870 
Rua Pe. Alois Kades 400/210 
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br
 


_______________________________________________________________________
Conheça o novo Cadê? - Mais rápido, mais fácil e mais preciso.
Toda a web, 42 milhões de páginas brasileiras e nova busca por imagens!
http://www.cade.com.br



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Update script
@ 2003-08-14 20:07  David Busby <busby@pnts.com>
  parent: Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
  2 siblings, 0 replies; 6+ messages in thread

From: David Busby @ 2003-08-14 20:07 UTC (permalink / raw)
  To: Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>; pgsql-php

Do:
    print $query;
in your code to look at the query you send, atoi = ASCII to Integer.
It is failing to convert a null string into integer, your query is
malformed.

/B

----- Original Message ----- 
From: "Ângelo Marcos Rigo" <angelo_rigo@yahoo.com.br>
To: <pgsql-php@postgresql.org>
Sent: Thursday, August 14, 2003 06:46
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 = pg_query($db, $query);

this is modificar_2.php :

<?php
$id = $_POST['id'];
$titulo = $_POST['titulo'];
$texto = $_POST['texto'];

include 'db.php';
$query = "UPDATE table SET titulo='$titulo',
texto='$texto' WHERE id='$id'";
$result = 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 = $_POST['id'];
$titulo = $_POST['titulo'];
$texto = $_POST['texto'];

include 'db.php';
$query = "SELECT id, titulo, texto FROM table WHERE
id='$id'";
$result = pg_exec($db, $query);
if (!$result) {printf ("ERROR"); exit;}
$numrows = pg_numrows($result);
$row=0;
?>
<table border=0 style="border: 1px solid black;">
<?php
do {
$myrow = pg_fetch_row ($result, $row);
//print_r($myrow);
print ("<tr><td>ID</td><td>$myrow[0]</td></tr>");
print ("<tr><td>Título</td><td><input type=text
value=$myrow[1] name=titulo size=150
maxlength=150></td></tr>");
print ("<tr><td>Texto</td><td><textarea cols=90
rows=20 value=$myrow[2]
name=texto>$myrow[2]</textarea></td></tr>");
$row++;
}
while ($row < $numrows);
?>

Thanks in advance


=====
Ângelo Marcos Rigo
AMR Informática
(51) 3348 0870
Rua Pe. Alois Kades 400/210
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br



_______________________________________________________________________
Conheça o novo Cadê? - Mais rápido, mais fácil e mais preciso.
Toda a web, 42 milhões de páginas 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




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Update script
@ 2003-08-14 23:22  CoL <col@mportal.hu>
  parent: Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
  2 siblings, 1 reply; 6+ messages in thread

From: CoL @ 2003-08-14 23:22 UTC (permalink / raw)
  To: pgsql-php

Hi,


Ângelo 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 = pg_query($db, $query);
> 
> this is modificar_2.php :
> 
> <?php
> 	$id = $_POST['id'];
> 	$titulo = $_POST['titulo'];
> 	$texto = $_POST['texto'];
> 
> 	include 'db.php'; 
> 	$query = "UPDATE table SET titulo='$titulo',
> texto='$texto' WHERE id='$id'";
print $query; You will get:
UPDATE table SET titulo='somthing',texto='text' WHERE id=''

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

C.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Update script
@ 2003-08-15 10:53  Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
  parent: CoL <col@mportal.hu>
  0 siblings, 0 replies; 6+ messages in thread

From: Ângelo Marcos Rigo @ 2003-08-15 10:53 UTC (permalink / raw)
  To: col@mportal.hu; +Cc: pgsql-php

Hi Col 

Thank´s for the postgre version note 
my problem was that i just forget the name=id atribute
in the textfield 

Best regards


 --- CoL <col@mportal.hu> escreveu: > Hi,
> 
> 
> Ângelo 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 = pg_query($db, $query);
> > 
> > this is modificar_2.php :
> > 
> > <?php
> > 	$id = $_POST['id'];
> > 	$titulo = $_POST['titulo'];
> > 	$texto = $_POST['texto'];
> > 
> > 	include 'db.php'; 
> > 	$query = "UPDATE table SET titulo='$titulo',
> > texto='$texto' WHERE id='$id'";
> print $query; You will get:
> UPDATE table SET titulo='somthing',texto='text'
> WHERE id=''
> 
> And your pg version is >= 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 

=====
Ângelo Marcos Rigo
AMR Informática 
(51) 3348 0870 
Rua Pe. Alois Kades 400/210 
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br
 


_______________________________________________________________________
Conheça o novo Cadê? - Mais rápido, mais fácil e mais preciso.
Toda a web, 42 milhões de páginas brasileiras e nova busca por imagens!
http://www.cade.com.br



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2003-08-15 10:53 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-14 13:46 Update script Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
2003-08-14 13:57 ` Viorel Dragomir <bc@vio.ro>
2003-08-14 16:55   ` Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>
2003-08-14 20:07 ` David Busby <busby@pnts.com>
2003-08-14 23:22 ` CoL <col@mportal.hu>
2003-08-15 10:53   ` Ângelo Marcos Rigo <angelo_rigo@yahoo.com.br>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox