guestabc Posted December 6, 2008 Share Posted December 6, 2008 Hi i'm trying to create a page where the administrator can delete a comment sent by a user by inputting the number of the comment id to delete that commnet. however i get the error message: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft JET Database Engine<br/><b>Description:</b> Data type mismatch in criteria expression.' in My code is as follows: <? if(isset($_POST['delete'])) { $DelID = ($_POST['DelID']); $sDELQUERY = "DELETE * FROM tblComment WHERE sCommentID='$DelID';"; $adoConnection->Execute( $sDELQUERY ); } ?> any help would be appreciated. thanks Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 6, 2008 Author Share Posted December 6, 2008 any ideas? Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 6, 2008 Author Share Posted December 6, 2008 also i forgot to mention that in the database the commentid is an autonumber but i think the php code is reading the input frm the user as text. how can i get this to match the correct datatype in the database? Quote Link to comment Share on other sites More sharing options...
peranha Posted December 6, 2008 Share Posted December 6, 2008 $sDELQUERY = "DELETE * FROM tblComment WHERE sCommentID='$DelID';"; should be $sDELQUERY = "DELETE FROM tblComment WHERE sCommentID='$DelID'"; You dont use * for delete statements, and also the ; was not needed. Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 7, 2008 Author Share Posted December 7, 2008 I've corrected the statement that you pointed out as shown below: $sDELQUERY = "DELETE FROM tblComment WHERE sCommentID='$DelID'"; however i am still getting a data mismatch error when i try to delete. In the database the sCommentID is set as a autonumber is this a problem? but im reading in a number into the form on the php page but i think its reading it as text maybe? Quote Link to comment Share on other sites More sharing options...
T Horton Posted December 7, 2008 Share Posted December 7, 2008 Hi Try this: $sDELQUERY = "DELETE FROM tblComment WHERE sCommentID='" .$DelID ."'"; Best Regards Tom Quote Link to comment Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 <?php if(isset($_POST['delete'])) { $DelID = isset($_POST['DelID'])?$_POST['DelID']:0; if ($DelID != 0) { $sDELQUERY = "DELETE * FROM tblComment WHERE sCommentID=$DelID"; $adoConnection->Execute( $sDELQUERY ); } } ?> Give that a try and see. Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 9, 2008 Author Share Posted December 9, 2008 I have tried both of the above <?php if(isset($_POST['delete'])) { $DelID = isset($_POST['DelID'])?$_POST['DelID']:0; if ($DelID != 0) { $sDELQUERY = "DELETE * FROM tblComment WHERE sCommentID=$DelID"; $adoConnection->Execute( $sDELQUERY ); } } ?> and... $sDELQUERY = "DELETE FROM tblComment WHERE sCommentID='" .$DelID ."' still not working. I am still getting the error that theres a data mismatch. Quote Link to comment Share on other sites More sharing options...
premiso Posted December 9, 2008 Share Posted December 9, 2008 <?php if(isset($_POST['delete'])) { $DelID = isset($_POST['DelID'])?intval($_POST['DelID']):0; if ($DelID != 0) { $sDELQUERY = "DELETE * FROM tblComment WHERE sCommentID=$DelID"; $adoConnection->Execute( $sDELQUERY ); } } ?> Try that, the intval function will convert the string to an integer. Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 10, 2008 Author Share Posted December 10, 2008 Thanks premiso the code below that you sent me with the intval function now deletes comments and no longer get a data mismatch error. However I have to submit the form twice for it to delete a comment as on the first submit nothing happens. any ideas? thanks <?php if(isset($_POST['delete'])) { $DelID = isset($_POST['DelID'])?intval($_POST['DelID']):0; if ($DelID != 0) { $sDELQUERY = "DELETE * FROM tblComment WHERE sCommentID=$DelID"; $adoConnection->Execute( $sDELQUERY ); } } ?> Quote Link to comment Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 Post the form code... Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 11, 2008 Author Share Posted December 11, 2008 <form name="delete" id="delete" method="post" action=""> <label for="DelID"><h4>Enter Conatact ID:</h4></label> <input type="text" name="DelID" id="DelID"><br /> <label for="button"></label> <input type="submit" name="del" id="del" value="DELETE"> </form> thanks Quote Link to comment Share on other sites More sharing options...
premiso Posted December 11, 2008 Share Posted December 11, 2008 <form name="delete_form" id="delete" method="post" action=""> <input type="hidden" name="delete" value="delete" /> <label for="DelID"><h4>Enter Conatact ID:</h4></label> <input type="text" name="DelID" id="DelID"><br /> <label for="button"></label> <input type="submit" name="del" id="del" value="DELETE"> </form> Try that and it should work. Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 11, 2008 Author Share Posted December 11, 2008 I've tried the code below that you sent but i still have the problem that i have to submit the form twice for it to delete the chosen comment. thanks <form name="delete_form" id="delete" method="post" action=""> <input type="hidden" name="delete" value="delete" /> <label for="DelID"><h4>Enter Conatact ID:</h4></label> <input type="text" name="DelID" id="DelID"><br /> <label for="button"></label> <input type="submit" name="del" id="del" value="DELETE"> </form> Quote Link to comment Share on other sites More sharing options...
premiso Posted December 11, 2008 Share Posted December 11, 2008 How are you testing that the comment was deleted? Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 11, 2008 Author Share Posted December 11, 2008 the comments are printed out on the screen (the same screen as the delete form) when the page refreshes the comment still appears that i tried to delete. the second time i submit the form that specific comment appears to of been delivered. i checked the database after the first time it still appears in the database after the first attempt and then the second time it has been deleted Quote Link to comment Share on other sites More sharing options...
premiso Posted December 11, 2008 Share Posted December 11, 2008 the comments are printed out on the screen (the same screen as the delete form) when the page refreshes the comment still appears that i tried to delete. the second time i submit the form that specific comment appears to of been delivered. i checked the database after the first time it still appears in the database after the first attempt and then the second time it has been deleted Are you re-retrieving the data? Post the code that does the comment display. Chances are you are retrieving the data before you execute the query. Since there is no delID of X the query does not error out, but it is also not modifying anything. Quote Link to comment Share on other sites More sharing options...
guestabc Posted December 11, 2008 Author Share Posted December 11, 2008 Thank you that was a bad error on my part. but thanks for the help people! 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.