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...
?>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to