[SOLVED]How to make a conditional insert in multiple tables? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [SOLVED]How to make a conditional insert in multiple tables? (/showthread.php?tid=12026) Pages:
1
2
|
[SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]earlyriser[/eluser] I want to make a conditional insert in multiple tables. My tables are: WINES: id, name, year. WINE_COMMENTS: id, user_id, wine_id, rating. and some user tables from Freak Auth Then, my form asks for a wine name, a wine year, a rating and it has a hidden field with the logged user. If the wine name is not in the database, the controller needs to -add a wine: id (incremental), name (from the form), year (from form) -add a comment: id (incremental), user_id (form), wine_id (recent added wine.id), rating(form). If the wine name is in the database, the controller needs just to -add a comment: id (incremental), user_id (form), wine_id (recent result wine.id), rating(form). This is my form Code: <?=form_open('wine/comment_insert'); ?> Code: function comment_insert() Please help me turning this pseudocode in the correct code. I have made the Blog tutorial, but it doesn't help me with this multiple insert. [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]Dready[/eluser] Hello, I guess : Code: if ($query->num_rows() > 0) //if it was found in wines.names oh, and welcome to CI ! [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]earlyriser[/eluser] Dready: thanks for your reply. I tried your code as you can see below, but I only got a blank page. Any advice? Code: function comment_insert() [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]Sumon[/eluser] you have no view page defined. so for successful case it shall show a blank page. so first check database for correct data inserted successfully and then use Code: redirect('yourcontroller/success_function'); [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]earlyriser[/eluser] Sumon: I have check the DB, but it doesn't insert data. I have made tests, with a dummy boolean variable in the IF and then it works. Then I think there is something wrong between the begin of the function and the IF. And yes, I don't have a success page, that will come later. [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]Sumon[/eluser] would you please try with Code: $this->db->where('name', '$_POST['name']'); Code: echo $query->num_rows(); [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]earlyriser[/eluser] I have added the success page. It still doesn't work with the IF clause. Something must be wrong there because nothing in the if o else is executed Code: //check if the wine is in database [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]earlyriser[/eluser] Sumon: [quote author="Sumon" date="1223002306"]would you please try with Code: $this->db->where('name', '$_POST['name']'); I put the above line and now the page where the form should be is blank. Then I tried with the next line with same result Code: $this->db->where('name', "$_POST['name']"); [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]Sumon[/eluser] what about Code: echo $query->num_rows(); [SOLVED]How to make a conditional insert in multiple tables? - El Forum - 10-02-2008 [eluser]earlyriser[/eluser] [quote author="Sumon" date="1223003201"]what about Code: echo $query->num_rows(); I did it. I got a blank page My current code is Code: function comment_insert() Thanks for your comments. |