Check if a value exist before posting
Hello friends,
Please could someone point me to my error in the code below.
I want to post an assessment for the previous year (2016). However, before the assessment is posted, I want the system to check if I have posted an application for that year 2016 by checking my UserID (uid) and the year. If I have done that already, it should popup a message alerting me that I have already posted for the previous year.
taxyr is the year field while DATE_SUB(CURDATE(), INTERVAL 1 YEAR) is used to calculate the previous year in MySQL. However, I am not getting any response whatsoever. The data is still posted even though the previous year 2016 is existing.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_assessment_frm")) {
$taxyr = strtolower($_POST['taxyr']);
$query = sprintf("select taxyr from tbl_tableassmt where uid='".$uid."' AND taxyr = DATE_SUB(CURDATE(), INTERVAL 1 YEAR)", mysql_real_escape_string($email));
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows > 0)
{
$message = "Error: You have already sent your assessment for the previous year.";
}
elseif($num_rows == 0)
{
$insertSQL = sprintf("INSERT INTO tbl_tableassmt (`uid`, incsrc, taxidno, salary, txxamt, gratuity, health, housing, assurance, pension, bizprft, allowances, obenefts, bonus, gaincome, conallowances, chgincome, taxyr, username) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['uid'], "int"),
GetSQLValueString($_POST['incsrc'], "text"),
GetSQLValueString($_POST['taxidno'], "text"),
GetSQLValueString($_POST['salary'], "double"),
GetSQLValueString($_POST['txxamt'], "double"),
GetSQLValueString($_POST['gratuity'], "double"),
GetSQLValueString($_POST['username'], "text"));
mysql_select_db($database_XXXXX_DB, $XXXXX_DB);
$Result1 = mysql_query($insertSQL, $XXXXX_DB) or die(mysql_error());
$insertGoTo = "upd_my_tax_assessment";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}
Thank you

