PHP and javascript onclick problem

Discussion in 'Programming' started by johneva, Mar 2, 2010.

  1. #1
    Hi

    Just having trouble getting a simple on click warning to work due to problem with quotes when I echo a link with the onclick function.

    Is there an easy way to add a warning for these delete links?

    Here is the delete.php pages code without the onclick fuction.

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    <title>Delete Page - Dual Controls Car Contol Panel</title>
    <link href="cp_css/loginmodule.css" rel="stylesheet" type="text/css" />
    </head>
      
      <body>
       <h1>Delete Form</h1>
       <p><a href="/dual_control_car_hire/control_panel">Control Panel</a></p>
    
    <ul>
    <?php 
    //If cmd has not been initialized
    if(!isset($cmd)) 
    {
       //display all the cars
       $result = mysql_query("select * from data order by make, model"); 
       
       //run the while loop that grabs all the cars scripts
       while($r=mysql_fetch_array($result)) 
       { 
          //grab the make, model and the ID
          $make=$r['make']; 
          $model=$r['model'];
          $id=$r['id'];
    
    	 //make the title a link
          echo "<li>";
          echo "<a href='delete.php?cmd=delete&id=$id'>Delete - $make $model</a>";
          echo "</li>";
        }
    }
    ?>
    
    <?
    if($_GET["cmd"]=="delete")
    {
    
      $id = $_GET['id'];
      
        $sql = "DELETE FROM data WHERE id=$id";
        $result = mysql_query($sql);
        echo "Row deleted!";
    }
    ?>
    
    </body>
    </html>
    PHP:

     
    johneva, Mar 2, 2010 IP
  2. ryantetek

    ryantetek Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    echo "<a href='delete.php?cmd=delete&id=$id' onclick='return confirm(\"Delete this message?\")'>Delete - $make $model</a>";
    Code (markup):
     
    ryantetek, Mar 2, 2010 IP
    johneva likes this.
  3. johneva

    johneva Well-Known Member

    Messages:
    1,480
    Likes Received:
    46
    Best Answers:
    1
    Trophy Points:
    170
    #3
    Ah awsome cheers
     
    johneva, Mar 2, 2010 IP
  4. ryantetek

    ryantetek Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    no problem mate ;)
     
    ryantetek, Mar 2, 2010 IP