While fetching rows from database I am facing very strange problem..... For me, the code seems okay.. If you think that if there is some error than please inform me...I will be thankful for you for your support.
This code is working fine for new entry means entrying in the else condition:
the error is as:
Undefined variable: db_deptid in <b>C:\xampp\htdocs\OMS\PHP\newdep.php</b> on line <b>17</b><br /> <br /> <b>Notice</b>: Undefined variable: db_deptname in <b>C:\xampp\htdocs\OMS\PHP\newdep.php</b> on line <b>20</b><br />
And my php code is as:
<?php
include('../connection2.php');
$lcl_depid = mysql_real_escape_string($_POST['depid']);
$lcl_depname = mysql_real_escape_string($_POST["depname"]);
$sql_select = "SELECT * FROM table_mstr_department where DeptId = '$lcl_depid'";
$sel_query = mysql_query($sql_select);
$row = mysql_fetch_row($sel_query);
if($row > 0){
while($val = mysql_fetch_array($sel_query, MYSQL_BOTH)) {
$db_deptid = stripslashes($val['DeptId']);
$db_deptname = stripslashes($val['DeptName']);
}
if($lcl_depid == $db_deptid){
echo "Department Id " .$lcl_depid ." has already been taken!";
}
else if($lcl_depname == $db_deptname){
echo "Department Name " .$lcl_depname ." has already been taken!";
}
}
else{
$query = "INSERT INTO table_mstr_department (DeptId, DeptName) VALUES ('$lcl_depid','$lcl_depname')";
if(mysql_query($query))
{
echo "Insertion Successfull!";
}
else
{
echo "Insertion failed!";
}
}
?>