Yes, I did not receive any replies to that message yesterday. Here is my
code (condensed) as well. What ends up happening is that when I write a
variable for a field that did have data, for example "cus034a", to the db it
shows a value of "0" when I intended it to be "NULL".
Thanks.
Zach
# partial table definition
username CHAR(6) NOT NULL,
password CHAR(8) NOT NULL,
int_id VARCHAR(4) NOT NULL,
cus034a TINYINT UNSIGNED NULL,
cus034b TINYINT UNSIGNED NULL,
cus034c TINYINT UNSIGNED NULL,
sat01 TINYINT UNSIGNED NULL,
PRIMARY KEY(password, int_id)
// php script
// INITIALIZE DATA ARRAY
function initialize_data()
{
// create array to store record
$data_array = array();
$data_array["username"] = "";
$data_array["password"] = "";
$data_array["int_id"] = "";
$data_array["cus034a"] = NULL;
$data_array["cus034b"] = NULL;
$data_array["cus034c"] = NULL;
$data_array["sat01"] = NULL;
...
...
...
return $data_array;
}
// CREATE ARRAY TO HOLD FLAT FILE
$file_array = array();
$file_array = file(DAT_FILE);
$count = count($file_array);
if ($count == 0)
echo "No records found in dat.cgi file.";
// initialize data array
$data_array = initialize_data();
// $i is the current element in the $file_array
// LOOP THRU FLAT FILE
while ($i < $count)
{
// extract header data
$data_array["username"] = trim(substr($file_array[$i], 0, 12));
$data_array["password"] = trim(substr($file_array[$i], 12, 8));
$data_array["int_id"] = trim(substr($file_array[$i], 20, 4));
// extract response data
for ($j = 0; $j < $data_array["num_responses"]; $j++)
{
$i++;
$extract_array = explode(",", $file_array[$i]);
if ($extract_array[0] == "cus034a")
{
$data_array["cus034a"] = $extract_array[1];
}
elseif ($extract_array[0] == "cus034b")
{
$data_array["cus034b"] = $extract_array[1];
}
elseif ($extract_array[0] == "cus034c")
{
$data_array["cus034c"] = $extract_array[1];
}
elseif ($extract_array[0] == "sat01")
{
$data_array["sat01"] = $extract_array[1];
}
...
...
...
else
{
echo "Could not process response data for int_id: $int_id" .
"and password: $password
recorded.";
}
} // end for
// WRITE RECORD TO DB TABLE
$date_time = date("Y-m-d H:i:s");
$result2 = mysql_query("INSERT INTO s999dat SET
username= '".
$data_array["username"] ."' ,
password= '".
$data_array["password"] ."' ,
int_id= '".
$data_array["int_id"] ."' ,
cus034a= '".
$data_array["cus034a"] ."' ,
cus034b= '".
$data_array["cus034b"] ."' ,
cus034c= '".
$data_array["cus034c"] ."' ,
sat01= '".
$data_array["sat01"] ."' ,
...
...
...
);
if (mysql_affected_rows() == 0)
{
echo "Error adding record to db." .
"int_id: $int_id" .
"and password: $password" .
mysql_error() . "";
exit;
}
$i++;
// INITIALIZE DATA ARRAY
$data_array = initialize_data();
} // end while
--
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]