hello i am working on a project where by, data is collected from a form, this data is posted from the form to a webservice and a database. they both work properly, but i need to put some checks in place.
i am try to halt the process flow of my functions based on when ever the first function fails.
the first function is the one that posts the data collected to a webservice. below :
<?php
require_once('includes/nusoap.php');
$wsdlfile = "https://niid.autoreglive.org/nia_api/service.asmx?wsdl";
$wsdlfile = "https://www.niid.org/NIA_API/Service.asmx?wsdl";
//$wsdlfile = "http://localhost:82/cscart/service/index.php";
$msg = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<Username>name</Username>
<Password>pass</Password>
<NiaNaicomID>nnn</NiaNaicomID>
<PolicyNo>TP/1/1</PolicyNo>
<InsuredName>Sunky Yaki</InsuredName>
<ContactAddress>Yaba Lagos</ContactAddress>
<GSMNo>08021231234</GSMNo>
<Email>a@b.c</Email>
<EffectiveCoverDate>2013-09-20</EffectiveCoverDate>
<ExpirationDate>2014-09-19</ExpirationDate>
<TypeOfCover>Comprehensive</TypeOfCover
><VehicleCategory>Saloon</VehicleCategory>
<EngineNo>uhdu</EngineNo>
<ChasisNo>dksdj</ChasisNo>
<VehicleColor>green</VehicleColor>
<YearofMake>1999</YearofMake>
<VehicleMake>Toyota</VehicleMake>
<RegistrationNo>gg11jj</RegistrationNo>
<OldRegistrationNo>11122</OldRegistrationNo>
<VehicleType>Saloon</VehicleType>
<EngineCapacity>4</EngineCapacity>
<VehicleModel>Camry</VehicleModel>
<SumAssured>233300</SumAssured>
<Premium>230</Premium>
<CoverNoteNo>1211</CoverNoteNo>
<CertificateNo>test 2</CertificateNo>
<GeographicalZone>North East</GeographicalZone>
</soap:Envelope>
";
$Username = '******';
$Password = '******';
$NiaNaicomID = '******';
$PolicyNo = $_POST['Policy_Number'];
$InsuredName = $_POST['Insured_Name'];
$ContactAddress = $_POST['Residential_Address'];
$GSMNo = $_POST['phone'];
$Email = $_POST['Email'];
$EffectiveCoverDate = $_POST['Date'];
$ExpirationDate = $_POST['Date_Expiry'];
$TypeOfCover = $_POST['Type_Of_Insurance'];
$VehicleCategory = 'null';
$EngineNo = $_POST['Engine_Number'];
$ChasisNo = $_POST['Chassis_Number'];
$VehicleColor = $_POST['Colour'];
$YearofMake = '2004';
$VehicleMake = $_POST['Make_Of_Car'];
$RegistrationNo = $_POST['Registeration_Number'];
$VehicleType = $_POST['Vehicle_Class'];
$EngineCapacity = '';
$VehicleModel = 'Model';
$SumAssured = 2.3;
$Premium = '2.3';
$CoverNoteNo = 'No note';
$CertificateNo = 'No certificate No';
$GeographicalZone = '6';
$params = array('Username' => $Username,
'Password' => $Password,
'NiaNaicomID' => $NiaNaicomID,
'PolicyNo' => $PolicyNo,
'InsuredName' => $InsuredName,
'ContactAddress' => $ContactAddress,
'GSMNo' => $GSMNo,
'Email' => $Email,
'EffectiveCoverDate' => $EffectiveCoverDate,
'ExpirationDate' => $ExpirationDate,
'TypeOfCover' => $TypeOfCover,
'VehicleCategory' => $VehicleCategory,
'EngineNo' => $EngineNo,
'ChasisNo' => $ChasisNo,
'VehicleColor' => $VehicleColor,
'YearofMake' => $YearofMake,
'VehicleMake' => $VehicleMake,
'RegistrationNo' => $RegistrationNo,
'VehicleType' => $VehicleType,
'EngineCapacity' => $EngineCapacity,
'VehicleModel' => $VehicleModel,
'SumAssured' => $SumAssured,
'Premium' => $Premium,
'CoverNoteNo' => $CoverNoteNo,
'CertificateNo' => $CertificateNo,
'GeographicalZone' => $GeographicalZone
);
$s = new nusoap_client($wsdlfile, 'wsdl');
//$s = new nusoap_client($wsdlfile);
// if (empty($proxyhost))
// {
// }else
// {
// $s->setHTTPProxy($proxyhost,$proxyport,$proxyusr,$proxypassword);
// }
$result = $s->call('Vehicle_Policy_Push', $params, '', '', false, true);
if($result){
print_r($result);
echo '<META HTTP-EQUIV="Refresh" Content="3; URL=account.php">';
}else{
echo '<META HTTP-EQUIV="Refresh" Content="3; URL=policy_active.php">';
}
?>
and this is the second function that i want to be halted whenever my first function fails below :
<?php
$con=mysqli_connect
("localhost","*******","*******","*******");
//Checkconnection
if(mysqli_connect_errno())
{
echo"FailedtoconnecttoMySQL:".mysqli_connect_error();
}
$check="SELECT * FROM transactions WHERE year_find = '$_POST[year_find]'";
$rs = mysqli_query($con,$check);
$data = mysqli_fetch_array($rs, MYSQLI_NUM);
if($data[0] > 1) {
echo '<META HTTP-EQUIV="Refresh" Content="3; URL=policy_active.php">';
}
else
{
$sql="INSERT INTO transactions(month_search,month,year_search,year,year_find,Username,Insured_Name,combined,Residential_Address,Telephone,Email,Make_Of_Car,Model,Engine_Number,Year_Of_Manufacture,Chassis_Number,Vehicle_Class,Colour,Registeration_Number,Product_Type,Premium,Policy_Number,Start_Date,Expiry_Date,Date_Begin,Type_Of_Insurance,Status, Transaction_id)VALUES('$_POST[month_search]','$_POST[month]','$_POST[year_year]','$_POST[newyear]','$_POST[year_find]','$_POST[Username]','$_POST[Insured_Name]','$_POST[combined]','$_POST[Residential_Address]','$_POST[phone]','$_POST[Email]','$_POST[Make_Of_Car]','$_POST[Model]','$_POST[Engine_Number]','$_POST[Year_Of_Manufacture]','$_POST[Chassis_Number]','$_POST[Vehicle_Class]','$_POST[Colour]','$_POST[Registeration_Number]','$_POST[Product_Type]','$_POST[Premium]','$_POST[Policy_Number]','$_POST[Date]','$_POST[Date_Expiry]','$_POST[Date_Begin]','$_POST[Type_Of_Insurance]','$_POST[Status]','$_POST[Transaction_id]')";
}
if(!mysqli_query($con,$sql))
{
die('Error:'.mysqli_error
($con));
}
echo '<META HTTP-EQUIV="Refresh" Content="3; URL=account.php">';
mysqli_close($con);
?>
the second function submits the data to a database. ordinary i was hoping the second function would fail to run when the first function failed, but imwas wrong, it moved on to the other function, which then submitted the unwanted data to the database.
so am wondering how i can halt the second function based on the failure of the first.