Help required in delete option

Discussion in 'PHP' started by realistic, Dec 11, 2009.

  1. #1
    The delete option is not working in table. Please help me

    here is my php script


    <?php
    $link = mysql_connect("localhost", "root", "")
    or die("Could not connect: " . mysql_error());
    mysql_select_db('taskmangment', $link)
    or die(mysql_error());
    ?>
    <?php
    switch ($_GET['action'])
    {
    case "remove":

    $sql = "DELETE FROM AddJob WHERE note_id='".$_GET['id']."'";
    break;
    }

    if (isset($sql) && !empty($sql)) {
    echo "<!--" . $sql . "-->";
    $result = mysql_query($sql)
    or die("Invalid query: " . mysql_error());
    }
    ?>

    <html>
    <head>
    <title>JobNotes</title>
    <style type="text/css">
    TD{color:#353535;font-family:Verdana, Arial, Helvetica, sans-serif}
    TH{color:#FFFFFF;font-family:Verdana, Arial, Helvetica,
    sans-serif;background-color:#336699;font-size:10pt}
    body,td {
    border-left:#FFF;
    font-size: 8pt;
    }
    a:link {
    color: #00F;
    text-decoration: none;
    }
    a:visited {
    text-decoration: none;
    color: #00F;
    }
    a:hover {
    text-decoration: none;
    color: #600;
    }
    a:active {
    text-decoration: none;
    color: #00F;
    }
    </style>
    <script>
    function deleteAlert(id){
    var conBox = confirm("Are you sure you want to delete");
    if(conBox){
    location.href="JobNotes.php?note_id="+ id + "&action=remove";
    }else{
    return;
    }
    }
    </script>
    <script type="text/javascript">
    function open_win()
    {
    window.open("New_Notes.php?action=add&id=",'','wid th=480,height=200,left=450,top=150');
    }

    </script>
    <script type="text/javascript">
    function edit_win(id)
    {
    var url="New_Notes.php?note_id="+id+"&action=edit";

    window.open(url,'','width=480,height=200,left=450, top=150,resizable=yes');
    }

    </script>

    <script type="text/javascript">
    function Att_win(id)
    {
    var url="AddNew1.php?note_id="+id+"&action=add1";

    window.open(url,'','width=480,height=200,left=450, top=150,resizable=yes');
    }

    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
    <body>
    <table border="0" width="100%" cellspacing="1" cellpadding="3"
    bgcolor="#353535" >
    <tr>
    <th bgcolor="#FFFFFF" align="center">
    JobNotes
    </th>
    <th colspan="2" align="left" bgcolor="#FFFFFF"><input type='button'
    value="AddNew" onClick="open_win()"></th>
    </tr>
    <?php
    $sql = "SELECT * FROM AddJob ORDER BY note_id";
    $result = mysql_query($sql)
    or die("Invalid query: " . mysql_error());
    while ($row = mysql_fetch_array($result)) {
    ?>
    <tr>
    <td bgcolor="#FFFFFF" width="77%">
    Asigned to:&nbsp;<?php echo $row['Ass']; ?>&nbsp;&nbsp;|&nbsp;&nbsp;Deliverd Date(M/d/Y):&nbsp;
    <?php echo $row['Ddate']; ?>&nbsp;&nbsp;|&nbsp;&nbsp;Verified By:
    </td>
    <td width="13%" rowspan="3" align="right" valign="top" bgcolor="#FFFFFF"><?php echo $row['date_time']; ?></td>
    <td width="10%" rowspan="3" align="right" valign="top" bgcolor="#FFFFFF">
    <a href="javascript:edit_win(<?php echo $row['note_id']?>)"><img src="Images/edit.gif" width="16"
    height="16" hspace="0" vspace="0" border="0"></a>
    <a href="javascript:deleteAlert('id')">Remove</a>
    </td>
    </tr>
    <tr>
    <td bgcolor="#FFFFFF"><?php echo nl2br($row['note']); ?></td>
    </tr>
    <tr>
    <td bgcolor="#FFFFFF"><a href="javascript:Att_win(<?php echo $row['note_id']?>)">Attchments</a></td>
    </tr>
    <?php
    }
    ?>

    </table>
    </body>
    </html>
     
    realistic, Dec 11, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    er - don't you pass a get var here:

    location.href="JobNotes.php?note_id="+ id +

    which is note_id

    and yet in the sql you refer to $_GET['id']

    :)
     
    dimitar christoff, Dec 11, 2009 IP