The function below, as its name suggests, registers/records the data from signup form into the database. In order to avoid table addresses from getting the wrong adressID(which references members(memberID)), I have to wrap the two insert queries into members and addresses respectively with autocommit and commit.
function register($un, $fname, $lname, $email, $pwd, $phone, $street, $city, $country, $postal, $state )
{
$this->conn->autocommit(FALSE);
$query_insert_members = "INSERT INTO members(fname, lname, uname, email, phone, password, joinDate) VALUES('".$fname."', '".
$lname."', '".$un."', '".$email."', '".$phone."', '".md5($pwd)."', NOW())";
$registerquery_members = $this->conn->query($query_insert_members);
$last_id = $this->conn->insert_id;
$query_insert_addresses = "INSERT INTO addresses(addressID, street, city, state, country, zip) VALUES('".$last_id."', '".
$street."', '".$city."', '".$state."', '".$country."', '".$postal."')";
$registerquery_addresses = $this->conn->query($query_insert_addresses);
if($this->conn->commit)
{
return true;
}
else
{
$affectd_rows = $this->conn->num_rows;
return $affectd_rows.$this->conn->error;
$this->conn->rollback();
}
}
It doesn't seem to commit anything and doesn't return any error messages either. I only get a blank message.