Welcome Guest, Not a member yet? Register   Sign In
Affected-rows question
#1

[eluser]Las3r[/eluser]
Hi there,

I got the following function:

Code:
function submit_ticket($category,$title,$content)
    {
        $db1 = $this->load->database('web', TRUE);
                
        $sql = 'INSERT INTO support_tickets
                (sender,category,ticket_title,ticket_contents,date,last_edit,is_answered)
                VALUES
                (?,?,?,?, GETDATE() , GETDATE() ,?) ';

        $submit = $db1->query($sql,array($_SESSION['username'],$category,$title,$content,0));
        if ($sql->affected_rows() == 1)
        {
        echo 'yay';
        return TRUE;
        }
        else
        {
        echo 'meh';
        return FALSE;
        }
}

The query is executed properly, data gets written in the database, however the affected rows won't show properly (should 1, since its an insert statement). I tried changing:

Code:
if ($sql->affected_rows() == 1)
to :
Code:
if ($submit->affected_rows() == 1)
and
Code:
if ($db1->$submit->affected_rows() == 1)


All without result.

Probably something small, can anyone shed some light on this?

Thanks.
#2

[eluser]pistolPete[/eluser]
The user guide tells you how it's working:
Code:
$this->db->affected_rows()

In your case:

Code:
$db1->affected_rows()
#3

[eluser]Las3r[/eluser]
Thanks pete, that's right.

I guess php-ing too much sometimes clouds the min. I tried a bit too much i guess ^^ !

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB