Log in

View Full Version : Records not deleting



JRF2k
03-19-2008, 07:08 PM
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


<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:


<?
// 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:


<?
$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!

city_coder
03-19-2008, 07:19 PM
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



header("Location: http://www.yoursite.com/adminpage.php");


cant help much more than that really sorry, someone else might be able to

JRF2k
03-19-2008, 07:54 PM
Thanks for the suggestions.

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

I will continue to search and hope for an answer.

JRF2k
03-20-2008, 02:32 AM
Can anyone help?

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

Thanks :)

thetestingsite
03-20-2008, 04:05 AM
Try this code for the deleting part (the parts I changed are highlighted):



<?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.

JRF2k
03-20-2008, 12:55 PM
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:


<?
$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?

JRF2k
03-20-2008, 02:30 PM
SCORRRRRRRRREEEEEEE!!!!!

Figured it out:


<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!

JRF2k
03-20-2008, 02:35 PM
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