Yohanne Posted April 3, 2014 Share Posted April 3, 2014 Hi coders, getting hard to insert, according to the image below. public function model_newtss($branch,$tssdate,$tss) { if($tss) { foreach($tss as $tss_s) { $tsss[] = $tss_s; } } $_implode = "('".implode("'),('",$tsss)."')"; $insert_tss = mysql_query("INSERT INTO code_tss(branch_id,tss_date,tss_trans_num) VALUES '$branch','$tssdate','$_implode'"); return $insert_tss; } Quote Link to comment Share on other sites More sharing options...
trq Posted April 3, 2014 Share Posted April 3, 2014 What? Quote Link to comment Share on other sites More sharing options...
Yohanne Posted April 3, 2014 Author Share Posted April 3, 2014 In image above "BRANCH" and "DATE" is not an array while "TSS #" is an array. BRANCH : <input type = "text" name = "branch" value = ""> DATE : <input type = "text" name = "date" value = ""> TSS NUMBER : <input type = "text" name = "tss[]" value = ""> //this line is, its up to a user how many input he/she want to add and defending on tss number. and now i am getting difficulties, how to insert together array/implode and none array or base on image above. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 3, 2014 Share Posted April 3, 2014 the sql syntax of your INSERT query is incorrect. you should be forming the sql query statement in a php variable so that you can echo it to see exactly what sql query statement is. Quote Link to comment Share on other sites More sharing options...
Yohanne Posted April 4, 2014 Author Share Posted April 4, 2014 (edited) thanks.. and now i change the scenario and im going explore something and it is not working well and please please let help me to correct this line of codes and i know it is possible. BRANCH : <input type = "text" name = "branch[]" value = ""> DATE : <input type = "text" name = "tssdate[]" value = ""> TSS NUMBER : <input type = "text" name = "tss[]" value = ""> USER : <input type = "text" name = "username[]" value = ""> public function model_newtss($branch,$tssdate,$tss,$username) { if($this->model_newtss) { foreach($this->model_newtss as $tss_s) { $tsss[] = $tss_s; } } $_implode = "('".implode("'),('",$tsss)."')"; $insert_tss = mysql_query("INSERT INTO code_tss(branch_id,tss_date,tss_trans_num,empid) VALUES ".$_implode.""); return $insert_tss; } Edited April 4, 2014 by JaysonDotPH Quote Link to comment Share on other sites More sharing options...
Yohanne Posted April 15, 2014 Author Share Posted April 15, 2014 (edited) Hi coders, Any help.. Edited April 15, 2014 by JaysonDotPH Quote Link to comment Share on other sites More sharing options...
Solution Yohanne Posted April 15, 2014 Author Solution Share Posted April 15, 2014 problem solve using for loop Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.