You want to check the exit code of the mysql insert before continuing, it's $? in bash. (basically a loop with an exit if $? != 0)
More info on exit codes: http://tldp.org/LDP/abs/html/exit-status.html
And bash scripting: http://www.tldp.org/LDP/abs/html/