Results 1 to 8 of 8

Thread: Records not deleting

  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Records not deleting

    Yes, it's me again. I've learned so much and progressed so far that I am to the point of finishing this.

    I have a file called AdminPage.php

    Code:
    <html>
    <body><?php
    $conn=odbc_connect('Warranty','','');
    if (!$conn)
      {exit("Connection Failed: " . $conn);}
    $sql="SELECT * FROM WarrantyInformation";
    $rs=odbc_exec($conn,$sql);
    if (!$rs)
      {exit("Error in SQL");}
    
    
    
    
    echo "<table border=1>";
    echo "<tr><th>ID</th>";
    echo "<th>Requester</th>";
    echo "<th>Owner</th>";
    echo "<th>Make/Model</th>";
    echo "<th>Serial Number</th>";
    echo "<th>Recieved</th>";
    echo "<th>Shipped</th>";
    echo "<th>Ticket Number</th>";
    echo "<th>Notes/Comments</th>";
    echo "<th>DELETE</th></tr>";
    
    
    while (odbc_fetch_row($rs))
    {
      $id=odbc_result($rs,"ID");
      $requester=odbc_result($rs,"Requester");
      $owner=odbc_result($rs,"Owner");
      $makemodel=odbc_result($rs,"MakeModel");
      $serialno=odbc_result($rs,"SerialNo");
      $received=odbc_result($rs,"Received");
      $shipped=odbc_result($rs,"Shipped");
      $ticketno=odbc_result($rs,"TicketNo");
      $notes=odbc_result($rs,"Notes");
      
      echo "<tr><td>$id</td>";
      echo "<td>$requester</td>";
      echo "<td>$owner</td>";
      echo "<td>$makemodel</td>";
      echo "<td>$serialno</td>";
      echo "<td>$received</td>";
      echo "<td>$shipped</td>";
      echo "<td>$ticketno</td>";
      echo "<td>$notes</td>";
      echo '<td><a href="delete.php?id='.$id['ID'].'">Delete</a></td></tr>';
    
    
      
    }
    odbc_close($conn);
    echo "</table>";
    ?></body>
    </html>
    Works great! Even the Delete link pulls the ID and puts it in there. I looked around the internet for the delete code and found:

    Code:
    <?
    // Connect database.
    include("connectdb.php");
    
    // Get values from form.
    $id=$_GET['id']; 
    
    // Do delete statement. 
    mysql_query("delete from phonebook where id='$id'");
    
    // Close database connection
    mysql_close(); 
    
    // Redirect to select.php.
    header("location:select.php"); 
    
    ?>
    My questions are: 1) Until now all my statements have been using ODBC, this uses MYSQL. Are they interchangable? 2) I have changed the above code to:

    Code:
    <?
    $conn=odbc_connect('Warranty','','');
    if (!$conn)
      {exit("Connection Failed: " . $conn);}
    
    // Get values from form.
    
    $id=$_GET['ID']; 
    
    
    // Do delete statement. 
    mysql_query("delete from WarrantyInformation where id='$id'");
    
    
    // Close database connection
    mysql_close(); 
    
    // Redirect to select.php.
    header("location:AdminPage.php"); 
    
    ?>
    When I click on the DELETE link it goes to a blank page, but never redirects back to AdminPage.php and the record has not been deleted.

    What am I not doing right?

    Thanks for the wonderful help thus far!

  2. #2
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default

    Im not too hot with the ODBC, iv used JDBC before. So i dont know about the connecting.

    The blank page you get is PHP's wonderfully descriptive error page...great isnt it :P

    with the delete as far as i know its not needed to have the single quotes around the variable but i dont think it makes a difference.

    2 things i can suggest, make sure that the delete will actually work...echo it out to the page...so comment out the header before so you get to see it or/and put the sql into the raw DB to see if it will process and there arent any syntax errors.

    The other thing is to have the full URL in the header redirect...soooo

    Code:
    header("Location: http://www.yoursite.com/adminpage.php");
    cant help much more than that really sorry, someone else might be able to
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  3. The Following User Says Thank You to city_coder For This Useful Post:

    JRF2k (03-19-2008)

  4. #3
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the suggestions.

    I am hacking and hacking, but nothing's working.

    I will continue to search and hope for an answer.

  5. #4
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    Can anyone help?

    Once I figure this out I am done and can stop bothering you fine folks!

    Thanks

  6. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try this code for the deleting part (the parts I changed are highlighted):

    Code:
    <?php
    $conn=odbc_connect('Warranty','','');
    if (!$conn)
      {exit("Connection Failed: " . $conn);}
    
    // Get values from form.
    
    $id=$_GET['ID']; 
    
    
    // Do delete statement. 
    odbc_exec($conn, "delete from WarrantyInformation where id='$id'");
    
    
    // Close database connection
    odbc_close($conn); 
    
    // Redirect to select.php.
    header("location:AdminPage.php"); 
    
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. The Following User Says Thank You to thetestingsite For This Useful Post:

    JRF2k (03-20-2008)

  8. #6
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    Still not working.

    I have attempted to make sure it is connecting to the database and pulling the information.

    I whittled the code down to this:

    Code:
    <?
    $conn=odbc_connect('Warranty','','');
    if (!$conn)
      {exit("Connection Failed: " . $conn);}
    
    
    // Get values from form.
    
    $id=$_GET['ID']; 
    
    echo "$id";
    
    
    // Close database connection
    odbc_close($conn); 
    
    
    ?>
    But when I click on the delete link I am still getting a blank page.

    What now?

  9. #7
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    SCORRRRRRRRREEEEEEE!!!!!

    Figured it out:

    Code:
    <html>
    <head><title></title></head>
    <body>
    <?PHP
    $conn=odbc_connect('Warranty','','');
    if (!$conn)
      {exit("Connection Failed: " . $conn);}
     
    $id=$_GET['id']; 
    
    $query = "DELETE FROM WarrantyInformation where id=$id";
    
    odbc_exec($conn, $query);
    
    
    odbc_close($conn);
    ?>
    </body>
    </html>
    Thanks again for all you guys' help!

  10. #8
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    Celebration too soon.

    It deleted IDs 1 and 2 but now the auto number is up to 12 and when I hover over the link it just shows 1 for both entries

    eg. http://myserver.com/delete.php?id=1

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •