Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]How to make a conditional insert in multiple tables?
#11

[eluser]Dready[/eluser]
Could you check the server error logs file and tell us if there is any relevant error in ?

@Sumon : I like more your previous avatar ! :-)
#12

[eluser]earlyriser[/eluser]
Dready: I have checked the error log

Error Log
Last 300 Error Log Messages in reverse order:

That's all, there is none
#13

[eluser]earlyriser[/eluser]
Now I got:

PHP Fatal error: Call to a member function on a non-object in /home/.../controllers/wine.php on line 49

whit the code
Code:
function comment_insert()
    {
        //check if the wine is in database
        $thename=$_POST['name'];
        $this->db->select('*');
        $this->db->from('wines');
        $this->db->where('name', $thename);
        $data['query']= $this->db->get();
        echo $query->num_rows();
    }
#14

[eluser]earlyriser[/eluser]
It works now.
I replaced the line
$data['query']= $this->db->get();
by
$result = $this->db->get();
But I am not sure why this was necessary. Could you help me to grasp that?

Then the view is the same and the controller code is
Code:
function comment_insert()
    {
        //check if the wine is in database
        $thename=$_POST['name'];
        $this->db->select('*');
        $this->db->from('wines');
        $this->db->where('name', $thename);
        $result = $this->db->get();    // <-- SOLUTION
        
         if ($result->num_rows() > 0) //if the wine is old, retrieve id
        {
            $dbrow = $query->row_array();
            $wine_id = $dbrow['id'];
        }
        else    //if the wine is old, add it
        {
            $this->db->insert('wines',array('name'=>$_POST['name'],'year'=>$_POST['year']));
            $wine_id = $this->db->insert_id();            
        }
        //finally insert wine comment
        $this->db->insert('wine_comments',array('user_id'=>$_POST['user_id'],'wine_id'=>$wine_id,'rating'=>$_POST['rating']));  
    }




Theme © iAndrew 2016 - Forum software by © MyBB