Jump to content

Delete not working


dodgei

Recommended Posts

As data is retrieved fromt the database I'm saving the records ID in a link so that if I want to delete it
I can click on the link and it will run the delete query.

The problem is that is not deleting the record.
What am I doing wrong??

[code]<?php

$odbc = odbc_connect ('accounting', 'root', '') or die('Could    Not Connect to ODBC Database!');
$sql = "select * from entry order by EntryID ASC";
  $results = @odbc_exec($odbc, $sql) or die("<tt>problem with $sql : " . odbc_errormsg() . "</tt>\n");

while($r = @odbc_fetch_array($results))
{


 
    echo "<tr><td>".$r['EntryID']."</td>";
echo "<td>".$r['DueDate']."</td>";
echo "<td>".$r['Merchant']."</td>";
echo "<td>".$r['Amount']."</td>";
    echo "<td><a href=" . $_SERVER['PHP_SELF'] . "?action=delete&row_id=" . $r['EntryID'].">delete</a></td></tr>";

 
}

if(isset($_GET['delete'])) {
  $sql = "delete from entry where EntryID = '" . $_GET['row_id'] . "'";
  @odbc_exec($odbc, $sql) or die("<tt>problem with $sql : " . odbc_errormsg() . "</tt>\n");
  echo "Record ".$_GET['row_id']."Deleted<br />";
  echo "<a href=\"http://www.merediencapital.com/ada/Invoices.php\">Return to main site</a>";
}

odbc_close($odbc);?>[/code]
Link to comment
Share on other sites

Thanks.

That got some wheels turning but it creates another problem for me.
The error that I got was this:

problem with delete from entry where EntryID = '1' : [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

I'm using odbc_fetch_array to get the record ID. But in the database the field is an auto-number type.
What to do?
Link to comment
Share on other sites

try doing this
[code]<?php
if(isset($_GET['action']) && $_GET['action'] == "delete") {
$id = $_GET['row_id'];
$sql = "delete from entry where EntryID = $id LIMIT 1";
?>[/code]

The limit 1 will make sure only one record is deleted, just incase you do something follish. Also access is very picky with the field types, by putting the id in single quotes it takes the id as a string. I am assuming that the id is an interger so you will get a mismatch type error.

Ray
Link to comment
Share on other sites

Actually your code is fine, the problem is with permissions. Access is a file like anything else, in order to modify it you have to have the right permissions to do so. Adjust your permissions and let me know. If you have a problem list what you are using.

OS?? Windows, Linux??
Web server?? IIS, Apache??

Ray
Link to comment
Share on other sites

It worked when I removed the "LIMIT 1" out of the sql statement.

But when I click on the link to return to the main page I get this error,

"CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:"

What is this? Does this mean that the links wont work on that page anymore?

After the delete I want to refresh the records to show the change. Suggestions?

Link to comment
Share on other sites

if you use the header function it will instantly go to the next page. You won't have time to read the result. Might want to do this

[code]echo "<META HTTP-EQUIV=\"Refresh\" content=\"2;url=Invoices.php\">";[/code]

change the 2 to whatever you like. That is the delay. So at least you will get the results then it will redirect.

Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.