Page 1 of 1

unable to add in it

Posted: Sun May 13, 2018 4:54 am
by newbaba
Hey guys i m just stuck here at this point where i am unable to add , but able to delete , edit and do all
kindly help me out in which part where is my error i m not able to find it my code is pasted below i m getting the error 1

Code: Select all



					<?php
						require_once ("../../../../libs/classes/DB.php");
						require_once ("../../../../libs/classes/MyMethods.php");
						require_once ("../../../../libs/classes/icons.php");
						$db = new DB(); $method = new MyMethods();$icon = new ICON();
						if ($method->isOk($_POST['name']) && $method->isOk($_POST['userid'])
							&& $method->isOk($_POST['userkey']) && $method->isOk($_POST['role']) & $method->isOk($_POST['Department'])) {
							$name= $_POST['name'];
							$role = $_POST['role'];
						    $userid = $_POST['userid'];
							$userkey = $_POST['userkey'];
							$userkey = $method->make_hash($userkey);
							$Department = $_POST['Department'];
							
							//search the same user id if available do not save
							$inputVars = array(
								':userid' => $userid,
								
							);
							
							
						/* Saad Code */	
						$SaadCode = array();
						$SaadString = '';
						$SaadRole = '';
						$SaadRole1 = '';
						
						foreach($db->getRecordSet("SELECT userid,Department,role FROM login WHERE userid ='$userid' ")
								as $row)
		
						{
									if ($SaadRole <> $role)
									{
																echo $SaadRole;

										echo "Im Here";
									$SaadString = $row['Department'];
									$SaadRole = $row['role'];
						}
						}
						echo $role;
						echo $SaadRole1;
						
						if ( empty($SaadString))
						{
						
												
									$inputsVars = array(
									':userid' => $userid,
									':userkey' => $userkey,
									':role' => $role,
									':user_status' => '1',
									':name' => $name,
									':Department' => $Department
								);
								
								$sqlInsert = "INSERT INTO login(
														userid,
														userkey,
														role,
														user_status,
														Discription,
														Department
														)
									  VALUES (
														:userid,
														:userkey,
														:role,
														:user_status,
														:name,
														:Department
														)";
									if($db->dbQuery($sqlInsert, $inputsVars))
									{		
									echo($method->sucMsg("Information: -", "User saved successfully"));
												} 
												else 
												{
									echo($method->errorMsg("Error: -", "User not saved due to server internel error 1"));
													}
							
						
							}
							
							
												
						
							elseif ($Department <>  $SaadString )
							{
							echo($method->errorMsg("Error", "Username/email already ID already exists"));
									
							} 
							
							elseif ($role == $SaadRole)
							{
							echo($method->errorMsg("Error", "Role  already assigned to this ID"));
							}
							else 
								{
							
						
									$inputsVars = array(
									':userid' => $userid,
									':userkey' => $userkey,
									':role' => $role,
									':user_status' => '1',
									':name' => $name,
									':Department' => $Department
								);
								
								$sqlInsert = "INSERT INTO login(
														userid,
														userkey,
														role,
														user_status,
														Discription,
														Department
														)
									  VALUES (
														:userid,
														:userkey,
														:role,
														:user_status,
														:name,
														:Department
														)";
									if($db->dbQuery($sqlInsert, $inputsVars)){		
									echo($method->sucMsg("Information: -", "User saved successfully"));
								} else 
								{
									echo($method->errorMsg("Error: -", "User not saved due to server internal error 2"));	
								}
									}
							 }
							
						
						else {
							echo($method->errorMsg("Error: -", "Empty fields are not allowed"));
						}
								
							
						/* Saad Code Ends Here */

							
					
					?>


i m getting the error 1

Re: unable to add in it

Posted: Sun May 13, 2018 2:01 pm
by Christopher
What is the error message returned by the database when you do the INSERT? The query with the problem appears to be here:

Code: Select all

									$inputsVars = array(
									':userid' => $userid,
									':userkey' => $userkey,
									':role' => $role,
									':user_status' => '1',
									':name' => $name,
									':Department' => $Department
								);
								
								$sqlInsert = "INSERT INTO login(
														userid,
														userkey,
														role,
														user_status,
														Discription,
														Department
														)
									  VALUES (
														:userid,
														:userkey,
														:role,
														:user_status,
														:name,
														:Department
														)";
									if($db->dbQuery($sqlInsert, $inputsVars)) {
									} else {
									        # What is the error from $db here?

Re: unable to add in it

Posted: Tue May 15, 2018 1:42 am
by newbaba
the query was the error
thanks for pointing it out