Jump to content

Query was empty


bscyb

Recommended Posts

Not quite

if(!$result)
{
echo 'error';
}
else
{
    // check that a record was deleted
    if(mysql_affected_rows() == 1)
    {
        echo 'Query deleted the record ' . $tID . ' successfully';
    }
    // record was not deleted
    else
    {
        echo 'The query did not delete the record' . $tID;
    }
}

 

if(mysql_query($result,$conn)){

        echo "$i  encountered an error.<br/>";

  } else {

        echo "$i successfully inserted.<br/>";

      }

That does need even relate to the OP's code.

Link to comment
Share on other sites

all he is trying to do is get a good message when it has deleted not if it has deleted he knows its deleting it.

So swapping the error message around would make a false positive a positive false.

He did not say he wanted to know if it has deleted anything from the mysql just to get a good message when the right id is used.

As he knows the rows are being deleted.

 

if(mysql_query($result,$conn)){

        echo "$i  encountered an error.<br/>";

  } else {

        echo "$i successfully inserted.<br/>";

      }

 

So what you're saying is that if the query executes without error, display an error message, and if the query fails to execute, display a success message? That's what that code does.

 

A syntactically correct DELETE query with a non-existent id will execute successfully. The only way to tell if the query had the intended result of actually deleting a record is with mysql_affected_rows().

Link to comment
Share on other sites

Not quite

if(!$result)
{
echo 'error';
}
else
{
    // check that a record was deleted
    if(mysql_affected_rows() == 1)
    {
        echo 'Query deleted the record ' . $tID . ' successfully';
    }
    // record was not deleted
    else
    {
        echo 'The query did not delete the record' . $tID;
    }
}

 

if(mysql_query($result,$conn)){

        echo "$i  encountered an error.<br/>";

  } else {

        echo "$i successfully inserted.<br/>";

      }

That does need even relate to the OP's code.

 

ok this code fixed it all now i get the correct message

when the record is deleted i get Query deleted the record

and if the record is not deleted i get The query did not delete the record

thanks allot

Link to comment
Share on other sites

works for me

if it looking at the false is correct but the code works then the error message is wrong

so swapping them round would give the opposite effect yes ?

 

As the CODE WORKS

 

A return of FALSE is not the correct result. FALSE means the query entirely failed to execute due to a syntax or other error, and the query could not possibly have deleted anything at all.

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.