0

I have a really silly issue i am trying to sort out. I have made this script that displays and deletes users from a database. however my alert function is not working. it performs the action of deleting the content in the database regardless of what I press when the alert appears. here is my code:

<?php include_once "includes/scripts.php"; ?>
<?php include_once "includes/connect.php";?>
<?php include_once "includes/cms_page_security.php";?>
<div id="cms_container"><br>
 <br>
 <h1>MANAGE USERS<img src="images/three_column_grid_line.png" alt="line"></h1>
 <p class="logout_btn"><a href="admin_cms.php">Back</a></p>
<?php
 $tbl="users";
 $sql = "SELECT * FROM users";
 $result = mysql_query($sql, $connect);
 while($rows = mysql_fetch_array($result)){
 echo $rows['user_name'];
 echo ' ';
 echo $rows['user_id']
?> 
 <a href="includes/delete_user.php?user_id=<?php echo $rows['user_id'] ?>" onClick="alertFunction()">delete</a>
<?php
} mysql_close();
?>
<script>
function alertFunction()
{
var r=confirm("Do you want to delete this user?");
if (r==true)
 {
 }
else
 {
 return (false);
 }
}
</script>
</div><!--cms_container-->
</body>
</html> 

I would just like the alert function to stop then process of deleting the content when i press cancel.

Lion
19.1k22 gold badges83 silver badges111 bronze badges
asked Oct 13, 2013 at 22:14
0

1 Answer 1

4

Change:

onClick="alertFunction()"

to:

onClick="return alertFunction()"

and in the function itself, change the false return to return false;. BTW, since a confirm returns true/false, you can change the first part of the condition to if (r)

answered Oct 13, 2013 at 22:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.