Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-708554
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-708574
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-710701
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-710703
Share on other sites

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 );
   }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-711757
Share on other sites

<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

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-712875
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-712884
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-712944
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-712976
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/135744-solved-delete/#findComment-712982
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.