I want to upload file if file is selected and if not selected then send null
value in db and if file size is grater then 3 mb send alert msj to user and in that conduction do not update query in db. I have tried this code but having problem in condutional statement please help me out with this with suitable code
my input type file tag name is AttachBills
:
if(isset($_POST["AddUnit"])){
echo "<script>alert(' in page subtion');</script>";
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$InvoiceNumber=$StockName=$UnitsAdded=$TotalCost=$AttachBills=$PaymentMode=
$PurchaseDate=$Comments="";
$InvoiceNumber = test_input($_POST["InvoiceNumber"]);
$StockName = test_input($_POST["StockName"]);
$UnitsAdded = test_input($_POST["UnitAdded"]);
$TotalCost = test_input($_POST["TotalCost"]);
$PaymentMode = test_input($_POST["PaymentMode"]);
$PurchaseDate = test_input($_POST["PurchaseDate"]);
$Comments = test_input($_POST["Comments"]);
$uploadOk = 1;
if($_FILES['AttachBills']['size'] > 0 ) {
echo "<script>alert('their is a file attachbills');</script>";
$Bill_File_Name=$_FILES["AttachBills"]["name"];
$Bill_Tmp=$_FILES["AttachBills"]["tmp_name"];
$Bill_Size=$_FILES["AttachBills"]["size"]/1024;
if($Bill_Size<=200) {
//New file name
echo "<script>alert(' filesize is less then 200 coundutoion');</script>";
//File upload path
$Bill_Path="uploads/" . $Bill_File_Name;
//function for upload file
if(move_uploaded_file($Bill_Tmp,$Bill_Path)){
$random=rand(1111,9999);
$Attach_Name=$random.$Bill_File_Name;
echo "<script>alert(' in if moved coundution');</script>";
} else {
echo "<script>alert('Problem With FileUpload. Please Try Again');</script>";
}
} else {
echo "<script>alert('Maximum upload file size limit is 200 kb');</script>";
$uploadOk=0;
}
} else {
if($uploadOk==1) {
echo "<script>alert(' in uploodad ok 1');</script>";
$UnitQuery="INSERT INTO `inventory_add_unit`(`InvoiceNumber`, `StockName`, `UnitsAdded`, `TotalCost`, `AttachBills`, `PaymentMode`, `PurchaseDate`, `Comments`) VALUES ('$InvoiceNumber','$StockName','$UnitsAdded','$TotalCost','$AttachBills','$PaymentMode','$PurchaseDate','$Comments')";
}
}
}