session_start(); global $scode; $linkID = mysql_connect("localhost", "root", "zangtang"); mysql_select_db("SciPark"); function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } //------------------------------------------------------------------------------------------------------------------------------------ // VERIFY FORM FUNCTION //--------------------------------------------------------------------------------------------------------------------------------------- function VerifyForm(&$values, &$errors) { if (strlen($values['VendorName']) == 0) $errors['VendorName'] = "Vendor's Name Required"; if(strlen($values['VendorAddr'])== 0) $errors['VendorAddr'] = "Address Required"; // if(strlen($values['VendorContactNo'])== 0) $errors['VendorContactNo'] = "Contact No Required"; if(strlen($values['VendorEmail']) != 0) { if (!preg_match("/^[\ a-z0-9._-]+@[a-z0-9.-]+\.[a-z]{2,6}$/i", $values['VendorEmail'])) $errors['VendorEmail'] = 'Email Address invalid'; } // if(strlen($values['VendorWebsite'])== 0) $errors['VendorWebsite'] = "Website Required"; // if(strlen($values['VendorPAN'])== 0) $errors['VendorPAN'] = "PAN details Required"; // if(strlen($values['VendorGST'])== 0) $errors['VendorGST'] = "GST Details Required"; if(htmlentities($values['VendorType']) == "Select") $errors['VendorType'] = "Vendor Name Required"; if(htmlentities($values['VendorType']) == "Other") { if(strlen($values['VendorTypeOther'])== 0) $errors['VendorTypeOther'] = "Other Required"; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //print_r($errors); return (count($errors) == 0); } //--------------------------------------------------------------------------------------------------------------------------------------- // DISPLAY FORM FUNCTION //--------------------------------------------------------------------------------------------------------------------------------------- function outputOptionList($list, $selected) { foreach ($list as $item) echo "\n"; } function DisplayForm($values, $errors) { // $chars = "abcdefghijkmnopqrstuvwxyz023456789"; $i=0; $d=date(d); $m=date(F); $n=date(n); $y=date(Y); $optionListMonth = array( array('Value' =>'Select', 'Text' => '(select Month)'), array('Value' =>'01', 'Text' => 'January'), array('Value' =>'02', 'Text' => 'February'), array('Value' =>'03', 'Text' => 'March'), array('Value' =>'04', 'Text' => 'April'), array('Value' =>'05', 'Text' => 'May'), array('Value' =>'06', 'Text' => 'June'), array('Value' =>'07', 'Text' => 'July'), array('Value' =>'08', 'Text' => 'August'), array('Value' =>'09', 'Text' => 'September'), array('Value' =>'10', 'Text' => 'October'), array('Value' =>'11', 'Text' => 'November'), array('Value' =>'12', 'Text' => 'December'), ); $optionVendorType = array( array('Value' =>'Select', 'Text' => '(select Type)'), array('Value' =>'Computer H.W./S.W.', 'Text' => 'Computer H.W./S.W.'), array('Value' =>'Educational Model', 'Text' => 'Educational Models'), array('Value' =>'Furniture', 'Text' => 'Furniture'), array('Value' =>'Scientific Products', 'Text' => 'Scientific Products'), array('Value' =>'Outdoor Equipments', 'Text' => 'Outdoor Equipments'), array('Value' =>'Other', 'Text' => 'Other'), ); $nextY = $y+1; //echo $nextY; $next2Y = $nextY+1; //echo $next2Y; $optionListYear = array( array('Value' => 'Select', 'Text' => "(select Year)"), array('Value' => '2018', 'Text' => "2018"), array('Value' => '2019', 'Text' => "2019"), array('Value' => '2020', 'Text' => "2020"), ); //print_r($optionListYear); ?>
} //--------------------------------------------------------------------------------------------------------------------------------------- $login = $_SESSION['AdminLogin'] ; $linkID = mysql_connect("localhost", "webuser", "zangtang"); mysql_select_db("SciPark"); $query0 = "SELECT * FROM AdminLogin WHERE `AdminLogin`='$login'"; $result0 = mysql_db_query("SciPark", $query0) or die ("could not query" . mysql_error()); $tung0=mysql_affected_rows(); $i=0; $j=0; if(isset($_SESSION['AdminLogin'])) { if($tung0) { if($_SERVER['REQUEST_METHOD'] == "POST") { //echo $_SESSION["TP"]; $formValues = $_POST; $formErrors = array(); //echo "the errors are :".$formValues."--".$Sname; if(isset($_POST["AddVendor"])) { if(!VerifyForm($formValues, $formErrors)) DisplayForm($formValues, $formErrors); else { //$formValues = $_POST; //$formErrors = array(); $VendorName = $_POST["VendorName"]; $VendorAddr = $_POST["VendorAddr"]; $VendorContactNo = $_POST["VendorContactNo"]; $VendorEmail = $_POST["VendorEmail"]; $VendorWebsite = $_POST["VendorWebsite"]; $VendorPAN = strtoupper($_POST["VendorPAN"]); $VendorGST = $_POST["VendorGST"]; $VendorType = $_POST["VendorType"]; $VendorTypeOther = $_POST["VendorTypeOther"]; if($VendorType == "Other") { $VendorType = $VendorTypeOther; } if (isset($VendorName) && isset($VendorAddr) && isset($VendorContactNo) && isset($VendorPAN) && isset($VendorGST) ) { print_r($_POST); $Fdate = date("Y-m-d"); $Tag = "0"; $ExtraInfo = ""; $query0 = "SELECT MAX(Vendor_ID) as Cntr FROM VendorMaster Order by Vendor_ID DESC"; $result0 = mysql_db_query("SciPark", $query0) or die ("could not query" . mysql_error()); $tung0=mysql_affected_rows(); if($tung0 != 0) { while ($r = mysql_fetch_array($result0)) { $Cntr = $r["Cntr"]; } $LastCnt = substr($Cntr, 1,3); $LastCnt++; $NewId= "V".str_pad($LastCnt, 3, "0", STR_PAD_LEFT); $LastCnt; echo $NewId; } else { $NewId = "V000"; } $query = "INSERT INTO VendorMaster VALUES ('$NewId','$VendorName','$VendorAddr','$VendorContactNo','$VendorEmail','$VendorWebsite','$VendorPAN','$VendorGST','$VendorType','A')"; //echo $query ; $result = mysql_db_query("SciPark", $query) or die ("could not connect to database".mysql_error()); $tung1=mysql_affected_rows(); if($tung1 != 0) { $_SESSION["VendorId"] = $NewId; header( 'Location: VendorAdded.php' ) ; } else { ?>
Problem with adding New Vendor into the Database...
} } else echo "Error found!!! Please fill the form correctly"; } //else close } else { $formValues = $_POST; $formErrors = array(); DisplayForm($formValues, $formErrors); }//echo $_POST["a_addr1"]; }//} ////////$_SESSIOM['H_HCBL'] = $H_HCBL; } else { DisplayForm(null, null); //echo "here1"; // } } } else { header( 'Location: Access_Denied.html' ) ; } ?>