This is regarding my add user php script. In that script iam executing three queries.
1. To add members to member table --> $qry_add
2. To assign members to laboratories --> $qry_lab
this is done by adding a raw to lab_employee table. Its a resultant table in M:N normalization between members table and lab table.
3. To add raw to sys_log table --> $qry_log
Sys_log table is for admins to capture that who is doing changes.
I think error is @ foreach loop. ($labid is an array and array values are correctly passed. Iam 100% sure. I have echo it and got values)
this is the php script
<?php
if(!isset($_SESSION['SESS_LOGIN']) || $_SESSION['SESS_TYPE'] !='admin')
{
echo '<script language="javascript">';
echo 'alert("Please login as ADMINISTRATOR to add a user");';
echo ' window.location.replace("index.html");';
echo '</script>';
}
else
{
include("config.php");
if (isset($_POST['emp_id']) && is_numeric($_POST['emp_id']))
{
$emp_id = $_POST['emp_id'];
}
if (isset($_POST['labid']) && is_numeric($_POST['labid']))
{
$labid = $_POST['labid'];
}
$login = mysql_real_escape_string($_POST['login']);
$password = mysql_real_escape_string($_POST['password']);
$type = mysql_real_escape_string($_POST['type']);
$email = mysql_real_escape_string($_POST['email']);
$password = md5($password);
$qry_add = " INSERT INTO members
(login, password, type, email, emp_id )
VALUES ('$login', '$password', '$type', '$email','$emp_id') ";
$qry_log = " INSERT INTO system_log (Entry_Date, login, Activity, Description )
VALUES (NOW(), '".$_SESSION["SESS_LOGIN"]."', 'ADD USER', '$login')";
$checkformembers = mysql_query("SELECT * FROM members WHERE login='$login'");
if(mysql_num_rows($checkformembers) != 0)
{
echo "<font color=red size=+1><br><br> Duplicate Entry. Please Verify User name ! </font><br><br><br>";
}
else
{
$result=mysql_query($qry_add);
if($result !=0)
{
if ($labid)
{
foreach ($labid as $lab_id)
{
echo 'You selected ',$lab_id,'<br />';
$qry_lab = " INSERT INTO lab_employee (lab_id, emp_id ) VALUES ('$lab_id', '$emp_id')";
$result2=mysql_query($qry_lab);
}
}
if($result2!=0)
{
$result1=mysql_query($qry_log);
if($result1!=0)
{
echo "<br><font color=green size=+1 >you have successfully added new user & successfully assigned to lab/labs ! </font> " ;
}else{}
}
else
{
echo "<br><font color=red size=+1 >Problem in assigning new user to a lab !</font><br>" ;
echo "ERROR - Successfully added new user but couldn't Assign to a lab !<br>";
$SQLError = "SQL ERROR: ".mysql_errno().". ".mysql_error()."<BR><BR>";
echo "$SQLError";
mysql_close();
}
}
else
{
echo "<br><font color=red size=+1 >Problem in Adding !</font><br>" ;
echo "ERROR - unable to save new username and password!<br>";
$SQLError = "SQL ERROR: ".mysql_errno().". ".mysql_error()."<BR><BR>";
echo "$SQLError";
mysql_close();
}
}
}
?>