The data being read dynamically into the array could contain values which
are NULL (the default) or numeric (if a numeric value exits). However, the
query is using a INSERT INTO and I can't seem to form this query to account
for either a NULL or numeric value.


Zach

-----Original Message-----
From: Rick Emery [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 8:18 AM
To: 'Zach Curtis'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Insert, Arrays, & Null


When you say "...account for either a numeric or NULL value ...", do you
mean SELECT a value that could be NULL?

If so, the query is "SELECT * FROM mytable WHERE cusa IS NULL || cusa >= 0"



-----Original Message-----
From: Zach Curtis [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 9:11 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Insert, Arrays, & Null


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


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

Reply via email to