[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2

Confirm deletion of a record using php and javascript

Asked by paulagabriel in PHP and Databases

Tags: php, confirm, javascript, delete, record

Hi

I have a mysql database table, for which I wish to allow my users to add, edit and delete their record.

Add and edit are ok, but when the user tries to delete their record, they should be prompted by a confirmation box.  If they press OK, then it should go ahead and delete, however, if they press cancel, it should not delete, but return them to the home page.

Currently, the OK button works fine, but if the user presses cancel, they are re-directed to the home page, but the record is still deleted.

Here is the code:

<?php
 $database = "Istanbul";
   $host="localhost";
   
   $link = mysql_connect($host)or die ("Couldn't connect");
   mysql_select_db($database, $link) or die ("Couldn't select database");

?>



<html>
<head>
  <title>Unsubscribe</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<style type="text/css">
<!--
-->
</style>
<link href="Tan.css" rel="stylesheet" type="text/css">
</head>
</head>
<body bgcolor="#FFFF66">
<?
if (!$_POST['unsubscribe']) {
?>
<center>
<form method="post" action="" name="theForm">
<table border=1 cellpadding=10 cellspacing=0 bgcolor = white>
<tr>
<td>
<font size=+1><b>Unsubscribe</b></font>
</td>
</tr>
<tr>
<td>
  Enter email:  <input name="email" type="text"  value="">
  </td>
</tr>
<tr>
<td colspan=2 align=center>    
<input type="submit" name="unsubscribe" value="Unsubscribe" >
</td>
</tr>
</table>
</form>
</center>

<?php
 }
 
if ($_POST['unsubscribe'])
{


    $email1 = trim($_POST['email']);
      
      if ( empty($email1))
       {    
     $error = true; // input validation failed
          echo "<span style=\"color:red\">Error!1 Please enter a valid email address.</span><br>\n";
              ?>
              <p>Click <a href="javascript:history.go(-1)">here</a> to go back.</p>
              <?
      }
      else if (!empty($email1))
      {
      
      $sql = "SELECT email FROM mailinglist WHERE email = '$email1'";
      $result = mysql_query($sql, $link) or die ("Couldn't execute query");
      while($a_row=mysql_fetch_row($result))
      {
      foreach($a_row as $field)
      $user = "$field";
      }
      if ($user)
      {
?>
      <script type="text/javascript">
      
       var answer = confirm ("Are you sure you want to unsubscribe?")
       if (answer==false)
        
      window.location="mainFrame.htm"
      
     
       else
      
      
       </script>
       <?php

       $query = "DELETE FROM mailinglist WHERE email LIKE '".$email1."' LIMIT 1";
     $result = mysql_query($query, $link) or die ("Couldn't add the data");
     
     if ($result)
       {
          echo "Success";
      }
     else
       {
       echo "<span style=\"color:red\">Error!2 Please enter a valid email address.</span><br>\n";
       ?>
              <p>Click <a href="javascript:history.go(-1)">here</a> to go back.</p>
              <?
       }
      
       }
      
      
      
      else if (!$user)
      {
       echo "<span style=\"color:red\">Error!3 Please enter a valid email address.</span><br>\n";
       ?>
              <p>Click <a href="javascript:history.go(-1)">here</a> to go back.</p>
              <?
       }       
}
} // End if post ok conditional
?>
</body>
</html>

Thank you for looking!
 
Loading Advertisement...
 
[+][-]03/18/04 08:53 PM, ID: 10630469Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/18/04 10:10 PM, ID: 10630730Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP and Databases
Tags: php, confirm, javascript, delete, record
Sign Up Now!
Solution Provided By: theprankstanator
Participating Experts: 3
Solution Grade: B
 
[+][-]03/19/04 04:04 AM, ID: 10632250Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89