CodeIgniter Forums

Full Version: Argument passed to [...] must be an instance of int, string given
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Hello, (sorry for ma english i am french)
I wrote this in my controller message.php :
Code:
function action_delete(int $idmessage)
    {
        mysql_query("DELETE * FROM Message WHERE IdMessage=$idmessage");
    }

and i want to pass argument to this method.

I do this in my view :
Code:
echo anchor('message/action_delete/'.$idmessage,'Delete');

I expected an int, and $idmessage=1...
I have this...
Quote:Argument passed to [...] must be an instance of int, string given

Someone could help me?

El Forum

[eluser]gigas10[/eluser]
PHP uses dynamic typing, that is you do not need to specify the variable type. Try this in your controller:
Code:
function action_delete($idmessage)
{
    $this->db->where('IdMessage', $idmessage);
    return $this->db->delete('Message');
}

If you want to ensure you are only getting an integer, you must check it yourself.

El Forum

[eluser]Unknown[/eluser]
thanks a lot!
that works Wink