A bill designed to prevent residents deemed mentally ill from buying guns advanced Thursday in the House, six weeks after a botched shooting at a Charleston school drew attention to a loophole in reporting.

The measure heading to the Judiciary Committee ensures the names of those determined mentally insane by a South Carolina court are put into a federal database for purposes of background checks for gun purchases.

“This is a public safety reporting bill,” said Rep. Leon Stavrinakis, D-Charleston, whose niece attends the school. “It takes the existing prohibition and addresses the fact that we have a glaring loophole.”

It’s already illegal to sell guns to someone who is mentally ill. But the lack of reporting means gun shops don’t get that information when they run a check.

Last month, authorities charged a 28-year-old woman with trying to fire a handgun at employees of Ashley Hall girls’ school during a busy afternoon carpool pickup. No one was hurt because she had loaded the gun incorrectly. Court records showed her disorders include schizophrenia and Asperger’s syndrome.

Ashley Hall parent Ana Murray said parents are outraged that a woman clearly judged insane could so easily buy a gun.

“Our teachers and children’s classmates came within a breath of dying,” she said. “This is not a hypothetical situation. I stand before you talking about the would haves and could haves, rather than another massacre. You only get that chance once. ... This cannot stand.”

Noting she’s a gun supporter, Murray called the measure simple and reasonable.