$errors['year_month'] = "* year month cannot be empty."; } elseif (!preg_match("/^[0-9]{6}\$/", $_POST['year_month'])) { $errors['year_month'] = "* Invalied year month."; } if (empty($_POST['rate'])) { $errors['rate'] = "* Rate cannot be empty."; } if (empty($errors)) { $year_month = trim(mysql_prep($_POST['year_month'])); $rate = trim(mysql_prep($_POST['rate'])); $bill = new Bill(); $bill->year_month = $year_month; $bill->rate = $rate; $td = new T_data(); $td->year_month = $year_month; $td->cal_totals(); $rslt = $bill->cal_bill(); /* $result = mysql_query("SHOW TABLES LIKE '$year_month'"); $tableExist = mysql_num_rows($result) > 0; if(!$tableExist){ echo '<script language="javascript">'; echo 'alert("error! First calculate the total weights!")'; echo '</script>'; }else{ $td->cal_totals(); $rslt=$td->cal_bill(); }