Sorry for the limited title. Go easy on me, i'm not quite advanced at PHP.
In my functions.php i've got the following 2 functions to see if the "recievers" or "senders" already exist.
function getSenderId($fromAddress){
global $database;
$check = $database->query("SELECT * FROM custMod_senders WHERE email = '$fromAddress'");
if($check->fetchRow() > 0){
$id = $check->fetchRow();
return $id['id'];
}else{
return 0;
}
}
function getReceiverId($toAddress){
global $database;
$check = $database->query("SELECT * FROM custMod_receivers WHERE email = '$toAddress'");
if($check->fetchRow() > 0){
$id = $check->fetchRow();
return $id['id'];
}else{
return 0;
}
}
Now in my the script i've got the following.
$from = $_SESSION['fromAddress'];
$to = $_SESSION['addresses'];
$std = $_SESSION['possibleStd'];
if (!is_array($to)){
$to = array($to);
}
foreach($to as &$address) {
if(getReceiverID($address) == 0){
echo 'receiver not found';
$database->query("INSERT INTO custMod_receivers (email, possibleStd) VALUES ('$address', '$std')");
}
if(getSenderID($from) == 0){
echo 'sender not found';
$database->query("INSERT INTO custMod_senders (email) VALUES ('$from')");
}
$send_id = getSenderID($from);
$receive_id = getReceiverID($address);
$database->query("INSERT INTO custMod_lt_send_rec (send_id, receive_id) VALUES ('$send_id', '$receive_id')");
};
Given that my vars, session and tablenames all exist and are available.. What is wrong with this loop or function setup?
The problem is in de last query within the foreach(). the link table is giving all kinds of crazy results.
EDIT: The problem is that the results in the DB are double, incomplete or missing. As if my 2 functions are giving false results...