I'm gathering info from a user and then adding them to a table.
$insert = "INSERT INTO jos_activeagents (RINGPHONE, AGENTUID, FNAME, LNAME) VALUES ('(618) 717-2054','".$result['AGTBRDIDMM']."','".$result['AGTFNAME']."','".$result['AGTLNAME']."')";
$set = mysqli_query($link,$insert);
AGENTUID
is a unique key. If a user tries to submit with a duplicate unique key, I get an error (of course).
Now, how would I go about knowing if and when an error occurred and then putting a response back to the page? I know of mysqli_get_warnings()
, but the PHP manual doesn't show any examples.
I have also tried looking for the AGENTUID
in the table first:
$check = "SELECT * FROM jos_activeagents WHERE AGENTUID = '".$agt."'";
$runcheck = mysqli_query($link,$check);
$rescheck = mysqli_fetch_assoc($runcheck);
if($rescheck != null){
echo 'This Agent ID is already enrolled.'
}
But this seems sloppy. Is there a better way do this?