Deleting entries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 66sprite
    New Member
    • Jul 2007
    • 3

    Deleting entries

    I am new to PHP and I am trying make a page that displays the entries in a table and then gives the option to delete a specific entry after checking it. I can get the page to display the entries and there is a link to delete the entry but it will not pass the variable to the second page that deletes the entry. Here is my code.

    This is the page that displays the entries:

    [code=php]<?php
    include 'datacon.php';

    $result = mysql_query("SE LECT * FROM stationfailuret est");

    echo "<table border='1'>
    <tr>
    <th>Station Failures</th>
    <td>ID</td>
    <td>Cube Number</td>
    <td>Phone Number</td>
    <td>Agent Name</td>
    <td>Agent ID</td>
    <td>Problem</td>
    </tr>";

    while($row = mysql_fetch_arr ay($result))
    {
    echo "<tr>";
    echo "<td><a href=\"list2.ph p?ID=";
    echo $row['id'];
    echo "\" TARGET=main>";
    echo "Delete</a></td>";
    echo "<td>".$row['id']."</td>\n";
    echo "<td>".$row['Cube_Number']."</td>\n";
    echo "<td>".$row['Phone_Number']."</td>\n";
    echo "<td>".$row['Agent_Name']."</td>\n";
    echo "<td>".$row['Agent_ID']."</td>\n";
    echo "<td>".$row['Problem']."</td>\n";
    echo "</tr>";
    }
    echo "</table>";

    mysql_close($co n);
    ?>

    Here is the code of the page that is supposed to delete the entry:

    <?php

    switch (ID)
    {
    default:
    echo "<b>";
    include 'datacon.php';

    $result = mysql_query("DE LETE FROM stationfailuret est WHERE id = '".$ID."'");

    mysql_close($co n);
    break;
    }
    ?>[/code]


    If I hard code the number of the ID into the second page it deletes the entry but not if I leave it to use the passed variable.

    Please Help
  • 66sprite
    New Member
    • Jul 2007
    • 3

    #2
    I changed the second page to:

    [code=php]<?php
    if($id=="")
    header("Refresh : 0;url=work.html ");
    else
    {
    include 'datacon.php';

    $query = "delete from stationfailuret est where id='".$id."'";
    $result = mysql_query($qu ery);
    header("Refresh : 0;url=index.php ");
    }
    ?>[/code]

    That way I could test to see if the variable is even passed and it comes up with the work.html. So for some reason the variable is not being passed.

    Thanks again

    Comment

    • 66sprite
      New Member
      • Jul 2007
      • 3

      #3
      actually i found the problem, thank you

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, 66sprite. Welcome to TSDN!

        Well, glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

        Comment

        Working...