I notice the INSERT statement only works when a unique email address is used (thats good as that field has a unique constraint in the mysql table). As a test I input the same email address ( so I thought the code in the catch block would be executed) and this is the result…
Warning: mkdir(): File exists in /home/luke69/public_html/thanks_provider.php on line 237
Warning: mkdir(): File exists in /home/luke69/public_html/thanks_provider.php on line 238
Warning: mkdir(): File exists in /home/luke69/public_html/thanks_provider.php on line 239
how can I make sure the three directories and the mail is sent only when a $primaryKey is set?
and the Catch block will run if it isn’t?
The question is why do you want it. The proper answer to your question depends on this one.
Assuming you want to show an ornate error message, as in your other question, let me warn you against it. Mind you’re [hopefully] not a sole user of your site. And this error message you’re putting so much effort on will be shown to a user who will have no idea what to do with it. while you will have no idea there was an error or what caused it.
how can I make sure the three directories and the mail is sent only when a $primaryKey is set?
That’s really easy. Set PDO in exception mode as explained here and get rid of the try..catch stuff in your code. And you will never see an mkdir command executed if insert fails.
thanks droopsnot, after putting that line of code in, if I try to enter a duplicate email the catch block is run, i commented out the error code cause its really only for me. Can I put a mail() in it so the error get emailed to me instead? how
catch(PDOException $e) {
echo '<div class="panel panel-default"style="margin:75px auto; width:960px">';
echo '<div class="panel-body">';
echo '<h4 class="text-danger">';
echo '<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> The email address ('.$email.') is being used by a provider.</h4>';
echo '<center><img src="images/fail.jpg" class="img-thumbnail img-responsive" /></center>';
echo "<br><a href='logout.php'>Try again (logout)?</a>";
echo '</div></div>';
// echo 'Error: ' . $e->getMessage();
}
Sorry, colshrapnel but I really dont want to get in over my head…
so, are you saying to change