I have attempted to insert data from an array into a table in which the
values are string and numeric or NULL. The string values are no problem
($password, $int_id), but when I try to insert a value which may be either
numeric or NULL (cusa, cusb, cusc) I can't produce a query that accounts for
either a numeric or NULL value. I have tried various combinations of queries
that include using ', ", and ., in the query, however those queries usually
result in either NULL values not be inserted into the table, a parse error,
or a failed query.


# partial mysql table definition
password CHAR(8) NOT NULL,
int_id VARCHAR(4) NOT NULL,
cusa TINYINT UNSIGNED NULL,
cusb TINYINT UNSIGNED NULL,
cusc TINYINT UNSIGNED NULL,
PRIMARY KEY(password, int_id)

// partial php script

// ***************************************
// the following (example) values are variable b\c the data are being read
into this script dynamically

// alpha values
$password = "test";
$int_id = "a";
// numeric or NULL values
$data_array = array();
$data_array["cusa"] = NULL; // can be numeric or NULL
$data_array["cusb"] = 0; // can be numeric or NULL
$data_array["cusc"] = 9; // can be numeric or NULL


// ***************************************
// this results in cusa = 0 in the table and not NULL
$query = "INSERT INTO s999dat SET
                password='$password',
                int_id='$int_id',
                cusa='$cus_array[cusa]',
                cusb='$cus_array[cusb]',
                cusc='$cus_array[cusc]'
                ";

Any thoughts on how I can create this query that can account for either a
numeric or NULL value coming from the dynamic array? Thank you.

_________________
Zach Curtis
Programmer Analyst
POPULUS
www.populus.com
_________________


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to