so I have this function below. At the very bottom I am returning $this->conn->lastInsertId()
. If i'm not mistaken this should be correct.
FILE #1
public function insertData($table, $qty, $data){
$errors = "";
$columns = $this->fetchColumnNames($table);
$column_list = implode(', ', $columns);
$values = array_fill(0, $qty, '?');
$value_list = implode(', ', $values);
$q = "INSERT INTO $table ($column_list) VALUES ($value_list)";
$stmt = $this->conn->prepare($q);
for($i = 1; $i < $qty + 1; $i++){
foreach($data as $key => $val){
if($key == $columns[$i-1]){
try{
if(is_numeric($val)){
$stmt->bindValue($i, $val, PDO::PARAM_INT);
}else{
$stmt->bindValue($i, $val, PDO::PARAM_STR);
}
}catch(PDOException $e){
print $e->getMessage();
}
}
}
}
try{
$stmt->execute();
}catch(PDOException $e){
$errors .= $e->getMessage();
print $errors;
}
return $this->conn->lastInsertId();
}
So moving on to my main file, I have the following line of code
FILE #2
error_reporting(E_ALL);
ini_set('display_errors', 1);
include '../../inc/config.php';
include 'ProcessApplication/ProcessApplication.php';
include 'ProcessApplication/ProcessApplicationQuery.php';
$processor = new ProcessApplicationQuery($CONN);
$processor->insertData("full_application", 17, $general);
if($processor->getConn()){
list($general, $phones) = $processor->processGeneralInfo($_REQUEST['general_information']);
print $processor->insertData("full_application", 17, $general);
}
If I remove the return line from File #1 and just print in File #2 nothing happens, and the program inserts into the database like so. For some reason this return line is causing the entire program to fail and 404. It's very odd I have never had this occur, so why would this return line cause this error?
===UPDATE===
So even weirder I have added the follow items to my files FILE #1
public function insertData($table, $qty, $data){
$errors = "";
$columns = $this->fetchColumnNames($table);
$column_list = implode(', ', $columns);
$values = array_fill(0, $qty, '?');
$value_list = implode(', ', $values);
$q = "INSERT INTO $table ($column_list) VALUES ($value_list)";
$stmt = $this->conn->prepare($q);
for($i = 1; $i < $qty + 1; $i++){
foreach($data as $key => $val){
if($key == $columns[$i-1]){
try{
if(is_numeric($val)){
$stmt->bindValue($i, $val, PDO::PARAM_INT);
}else{
$stmt->bindValue($i, $val, PDO::PARAM_STR);
}
}catch(PDOException $e){
print $e->getMessage();
}
}
}
}
try{
$stmt->execute();
}catch(PDOException $e){
$errors .= $e->getMessage();
print $errors;
}
}
public function getApplicationid(){
$query = "SELECT id FROM eagle.full_application ORDER BY create_date DESC LIMIT 1";
$id = null;
foreach($this->conn->query($query) as $row){
$id = $row['id'];
}
return $id;
}
FILE #2
error_reporting(E_ALL);
ini_set('display_errors', 1);
include '../../inc/config.php';
include 'ProcessApplication/ProcessApplication.php';
include 'ProcessApplication/ProcessApplicationQuery.php';
$processor = new ProcessApplicationQuery($CONN);
$processor->insertData("full_application", 17, $general);
if($processor->getConn()){
list($general, $phones) = $processor->processGeneralInfo($_REQUEST['general_information']);
$processor->insertData("full_application", 17, $general);
echo $processor->getApplicationId();
}
I added a new method, and attempted to print it. I still get the error in which the files 404. It is really odd. I hope this helps out on the solution, because I am stumped.