Forum Moderators: coopster
<?php
//variable declaration
$customerid = '257';
// DEBUG - get type => string
echo gettype($customerid);
//db settings
$dbconf = include '../config/dbConfig.php';
//storage array declaration
$arr = array();
//declaring result as TRUE: we assume all values entered are found in array
$result = TRUE;
//we connect to db host
$con = mysql_connect($dbconf["host"], $dbconf["user"],$dbconf["password"]) ;
if (!$con) {
die('Could not connect: ' . mysql_error());
}
//we connect to database
$db_selected = mysql_select_db($dbconf["db"], $con) or die ("Couldn't select the database.");
if (!$db_selected) {
die ('Could not use '.$dbconf["db"].' : ' . mysql_error());
}
//we get a list of customer ids.
$result=mysql_query("select distinct customerid from cases where status!='Closed'");
while($row=mysql_fetch_array($result)) {
$arr[] = $row['customerid'];
}
// DEBUG - outputs contents => works! Approx. 300+ customer ids
print_r($arr);
// DEBUG - get type => array!
echo gettype($arr);
//we check if input matches any value in array.
(bool)$result = in_array($customerid, $arr);
//we close databse connection and return boolean.
mysql_close($con);
if ((bool)$result == FALSE) {
echo 'not in array';
} else {
echo 'in array';
}
?>
...
$customerid = $_POST['customerid'];
$case_status = $_POST['status_change'];
/*
* Check customerid validity.
*/
$arr = array();
// DEBUG - get type => string
echo gettype($customerid);
//we get a list of customerids.
$result=mysql_query("select distinct customerid from cases where status!='Closed'");
while($row=mysql_fetch_array($result)) {
$arr[] = $row['customerid'];
}
// DEBUG - outputs contents => empty!
print_r($arr);
// DEBUG - get type => array
echo gettype($arr);
//we check if input matches any value in array.
(bool)$result = in_array($customerid, $arr);
//did we return FALSE?.
if ((bool)$result == FALSE) {
echo 'not in array' . (bool)$result;
} else {
echo 'in array' . (bool)$result;
}
$result=mysql_query("select distinct customerid from cases where status!='Closed'");
while($row=mysql_fetch_array($result)) {
//$arr[] = $row['customerid'];
print_r($row);
}
if ((bool)$result == FALSE)