dodgei Posted January 25, 2007 Share Posted January 25, 2007 As data is retrieved fromt the database I'm saving the records ID in a link so that if I want to delete itI 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] Quote Link to comment Share on other sites More sharing options...
zq29 Posted January 25, 2007 Share Posted January 25, 2007 [code]<?php//Try replacing this:if(isset($_GET['delete'])) {//With this:if(isset($_GET['action']) && $_GET['action'] == "delete") {?>[/code] Quote Link to comment Share on other sites More sharing options...
dodgei Posted January 25, 2007 Author Share Posted January 25, 2007 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? Quote Link to comment Share on other sites More sharing options...
craygo Posted January 25, 2007 Share Posted January 25, 2007 try doing this[code]<?phpif(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 Quote Link to comment Share on other sites More sharing options...
dodgei Posted January 25, 2007 Author Share Posted January 25, 2007 When I do that I get this error.problem with delete from entry where EntryID = 1 LIMIT 1 : [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'EntryID = 1 LIMIT 1'. Quote Link to comment Share on other sites More sharing options...
craygo Posted January 25, 2007 Share Posted January 25, 2007 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 Quote Link to comment Share on other sites More sharing options...
dodgei Posted January 25, 2007 Author Share Posted January 25, 2007 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 ErrorThe 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? Quote Link to comment Share on other sites More sharing options...
craygo Posted January 25, 2007 Share Posted January 25, 2007 Try using the reletive link rather than the full url[code]echo "<a href=\"Invoices.php\">Return to main site</a>";[/code]That is if Invoices is in the current directory you are inRay Quote Link to comment Share on other sites More sharing options...
dodgei Posted January 25, 2007 Author Share Posted January 25, 2007 That worked great. Thanks a lot.One last thing. How can I get it to do it automatically after the delete? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 25, 2007 Share Posted January 25, 2007 [quote author=dodgei link=topic=124030.msg513483#msg513483 date=1169757963]That worked great. Thanks a lot.One last thing. How can I get it to do it automatically after the delete?[/quote]use the [url=http://www.php.net/header]header()[/url] function. Quote Link to comment Share on other sites More sharing options...
craygo Posted January 25, 2007 Share Posted January 25, 2007 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 Quote Link to comment Share on other sites More sharing options...
dodgei Posted January 25, 2007 Author Share Posted January 25, 2007 thanks crayco and boo_lolly. I'm not sure how the header function works but the refreshworked great.crayco, can I do half seconds?? or just full? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.