Am trying to insert in to the same table two values from the same form. if counter equals to 1, do an update , else do an insert.
only the insert part is working, it looks like my counter script is not working,any help?
$counter=0;
$sre_log_num = 0;
$sre_log_result = mysql_QUERY("select count(*) As counter FROM sre_log WHERE vreg ='$vreg' AND id ='$id'");
$sre_log_num = mysql_numrows($sre_log_result);
$i = 0;
while($i < $sre_log_num)
{
$counter = mysql_result($sre_log_result,$i,"counter");
$i++;
}
if ($counter ==0 )
{
$sql = "insert INTO sre_log
(com_name,loc,name_mech,vtype,vreg,last_startdate,due_end_date,mileage,cur_date)
values
('$com_name','$loc','$name_mech','$vtype','$vreg','$last_startdate','$due_end_date','$current_mileage','$cur_date')";
}else{
$sql = "UPDATE sre_log SET
com_name='$com_name',loc='$loc',name_mech='$name_mech',vtype='$vtype',last_startdate='$last_startdate',due_end_date='$due_end_date',mileage='$current_mileage',cur_date='$cur_date' WHERE vreg='$vreg'";
}
mysql_query($sql);