-1
Hello. I’m having some trouble inserting values into a table.
Explaining better, I get the AID generated in Account and need to insert it in Login. I was successful in consulting the AID generated in Account but I have problems inserting it, the error is as follows:
Notice: Array to string Conversion & Fatal error: Uncaught Pdoexception: SQLSTATE[22018]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Failed to convert the nvarchar 'Array' value to the int data type.
The word array is to be the generated AID number, but in the error it sends with the word Array, but in my var_dump ($result) it displays the number, it confuses me a little.
Follows the code:
public function save(){
$query = "insert into Account(UserID, UGradeID, PGradeID, RegDate, Name, Email)values(:userid, 0, 0, GETDATE(), :name, :email)";
$stmt = $this->db->prepare($query);
$stmt->bindValue(':userid', $this->__get('userid'));
$stmt->bindValue(':name', $this->__get('name'));
$stmt->bindValue(':email', $this->__get('email'));
//$stmt->bindValue(':password', $this->__get('password'));
$stmt->execute();
$sql = "SELECT AID FROM ACCOUNT WHERE UserID = :userid";
$statement = $this->db->prepare($sql);
$statement->bindValue(':userid', $this->__get('userid'));
$statement->execute();
$result = $statement->fetch(\PDO::FETCH_ASSOC);
$result['AID'];
//$result->result;
print_r($result);
$insert = "INSERT INTO LOGIN(UserID, AID, Password) VALUES (:userid, :result, :password)";
$stmt2 = $this->db->prepare($insert);
$stmt2->bindValue(':userid', $this->__get('userid'));
$stmt2->bindParam(':result', $result);
$stmt2->bindValue(':password', $this->__get('password'));
$stmt2->execute();
return $this;
}
I appreciate your willingness to help me, but I figured out the problem. It was the way in which I accessed the result query that was wrong, it was necessary to assign another variable and do the search by AID. In this case of the main post, it was recovering all query, not only AID.
– M. Borges