if ($_SERVER["REQUEST_METHOD"] == "POST") { // Connect to server and select databse. $link = new mysqli($servername, $username, $password, $dbname); if ($link->connect_error) { die("Connection failed: " . $link->connect_error); } // useremail to be deleted sent from form $useremail = $_POST['useremail']; $sql = "SELECT * FROM Account WHERE email='{$useremail}'"; $result = $link->query($sql); $count = $result->num_rows; // if account is found if ($count == 1) { $row = $result->fetch_assoc(); $user_id = $row['user_id']; deleteRecipes($user_id, $link); //delete all recipe information deleteCookbooks($user_id, $link); //delete all cookbook information $sql = "DELETE FROM Account WHERE user_id = '{$user_id}'"; if ($link->query($sql) != true) { //unsuccessful query echo "ERROR: Could not able to execute {$sql}. " . $link->connect_error; } else { $success = "User with email: " . $useremail . " has been deleted."; } } else { $emailerror = "* No account exists with this email"; } mysqli_close($link); //close connection
<script> location.href = "http://<?php echo $_SERVER['HTTP_HOST'] . get_dirname($_SERVER['PHP_SELF']) . "/recipe-detail/" . cleanurl($recipe_alias); ?> "; </script> <?php } else { ?> <script> location.href = "http://<?php echo $_SERVER['HTTP_HOST'] . get_dirname($_SERVER['PHP_SELF']) . "/recipe"; ?> "; </script> <?php } } else { if ($_POST['btn-edit-recipes'] == "Delete") { deleteRecipes($recipe_id); ?> <script> location.href = "http://<?php echo $_SERVER['HTTP_HOST'] . get_dirname($_SERVER['PHP_SELF']) . "/recipe"; ?> "; </script> <?php } } }