update after select doesn't update... - Mailing list pgsql-php

From Dave VanAuken
Subject update after select doesn't update...
Date
Msg-id DBEIKNMKGOBGNDHAAKGNEELLLDAA.dave@hawk-systems.com
Whole thread Raw
List 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...
?>


pgsql-php by date:

Previous
From: Jaume Teixi
Date:
Subject: Re: WWW-Authentication and Postgresql [sample_code_inline]
Next
From: "Davis, Ricardo C."
Date:
Subject: Re: WWW-Authentication and Postgresql