update after select doesn't update...

From: "Dave VanAuken" <dave(at)hawk-systems(dot)com>
To: <pgsql-php(at)postgresql(dot)org>
Subject: update after select doesn't update...
Date: 2002-01-03 05:29:48
Message-ID: DBEIKNMKGOBGNDHAAKGNEELLLDAA.dave@hawk-systems.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

Am retrieveing an "available" ipaddress from a table, then later trying to
perform an update to "assign" the address to an id. The update produces no
error, but doesn't update either. Must be overlooking something but can't place
a finger on it.

Table "host_ipaddress"
Attribute | Type | Modifier
-----------+---------+----------
server | text | not null
type | text |
hostnum | integer | not null
address | text |
Index: host_ipaddress_pkey

<?PHP
# Variables
$database = ***pg_connect statement***
$hostnum=2; # client reference number
$primipaddr=AssignPrivateIP($hostnum,'web'); #function returns IP address

# Function
function AssignPrivateIP($hostnumber,$server) {
global $database;
$query = "SELECT address FROM host_ipaddress WHERE server='$server' AND
type='private' AND hostnum=0 LIMIT 1";
$result = pg_exec($database,$query);
if(pg_numrows($result)==0) {
$return=0;
} else {
$row = pg_fetch_array($result,0);
$return=$row[0];
}
return $return;
}

# Queries

# following does not work, the hostnum in the database table stays at 0
$query="UPDATE host_ipaddress SET hostnum=$hostnum WHERE address='$primipaddr'";

# the following updates all records for the server/of type priv to 2
# **EXCEPT** the IP address we retrieved from the function (which we want to
update)
$query="UPDATE host_ipaddress SET hostnum=2 WHERE server='web' AND type='priv'";

...appropriate exec etc...
?>

Browse pgsql-php by date

  From Date Subject
Next Message Davis, Ricardo C. 2002-01-04 20:33:40 Re: WWW-Authentication and Postgresql
Previous Message Jaume Teixi 2002-01-02 14:37:05 Re: WWW-Authentication and Postgresql [sample_code_inline]