I have a question on executing query inside IF statement. I will start with how i want the process to run. Initially i have an excel file that i want to upload into MYSql database. Using PHPExcel, i am able to get the data from the excel file. Now, what i want to do is for each data inside the excel file, it will compare with existing data inside database. If the data is matched, then it will execute the query to insert into success table, but if the data is not matched, it will execute query to insert into fail table.
Here is my code, the code now just skip the IF condition and execute the fail condition.
$query1 = "SELECT EXISTS(SELECT 1 FROM part WHERE partno = :partno)";
$statement1 = $connect->prepare($query1);
$query2 = "INSERT INTO stock (userid, vendorid, partno, partname)
VALUES (:userid, :vendorid, :partno, :partname)";
$statement2 = $connect->prepare($query2);
$query3 = "INSERT INTO fail (userid, vendorid, partno, partname)
VALUES (:userid, :vendorid, :partno, :partname)";
$statement3 = $connect->prepare($query3);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for($row=2; $row<=$highestRow; $row++)
{
$statement1->execute(
array(
':partno' => $worksheet->getCellByColumnAndRow(0, $row)->getValue()
)
);
if ($statement1=="1"){
$statement2->execute(
array(
':userid' => $_SESSION['user_id'],
':vendorid' => $_SESSION['vendorid'],
':partno' => $worksheet->getCellByColumnAndRow(0, $row)->getValue(),
':partname' => $worksheet->getCellByColumnAndRow(1, $row)->getValue(),
)
);
}
else{
$statement3->execute(
array(
':userid' => $_SESSION['user_id'],
':vendorid' => $_SESSION['vendorid'],
':partno' => $worksheet->getCellByColumnAndRow(0, $row)->getValue(),
':partname' => $worksheet->getCellByColumnAndRow(1, $row)->getValue(),
)
);
}
}
}
Any help is appreciated. Thanks