samf_20 Posted September 2, 2008 Share Posted September 2, 2008 Hi, I am creating an online form which should take information to from one page using a multiple-select box then display the selected fields in order confirmation page. This part of the code works fine, Then I press the submit (complete order) button and the information should then get stored into the MySQL database as a string. So if I selected jan,feb and apr it will store into MySQL like jan,feb,apr all in the same field. I think the main problem is that the information that is stored in the confirmation page is not being registered with the final order complete page. Here is the code: FirstPage: <select name="ilm[]" size="7" multiple="multiple"> <option value="January"> January </option> <option value="February"> February </option> <option value="April"> April </option> <option value="May-Buyers-Guide"> May Buyers Guide </option> <option value="July"> July </option> <option value="August"> August </option> <option value="October"> October </option> </select></center> </td> Just a normal Multiple-select table. Second page: <?php $_SESSION['details'] =$_POST['ilm']; $info2=$_SESSION['details']; if ($info2){ // $str=implode(",", $info2); $str=''; foreach ($info2 as $t){ $str.=$t.', '; } $str=trim ($str,', '); echo $str.'<br>'; } ?> This is the code I use to display the select information from the table as a string. Third Page: This is the code that I am using to try and put the string into mysql $ilm = $_SESSION['details']; foreach($ilm as $value) { $str = implode(',' , $ilm); echo $str; } foreach($ilm as $value) { $insert="INSERT INTO dealerguide (ilmissue) VALUES ('$str')"; } mysql_query($insert); I have tried echo'ing the string and it does not display the it probably meaning there is something else wrong which I cannot find. It seems not to find the on the seconds page therefore not inserting it into the MysQl database. Any help will be appreciated. Thanks PS: I have got SESSION_Start on all the pages at the very top. Also the code does not display teh forms thats because I would be sending you about 700lines of code that is unnecessary. CODE <form name="form1" method="post" action="./onlineFormPage2.php"> all of the form headers look like this and are pointing to the correct php page. Quote Link to comment https://forums.phpfreaks.com/topic/122347-phpmqsql-problem-data-not-being-inserted/ Share on other sites More sharing options...
JonnoTheDev Posted September 2, 2008 Share Posted September 2, 2008 This is incorrect. You do not implode in a loop $ilm = $_SESSION['details']; foreach($ilm as $value) { $str = implode(',' , $ilm); echo $str; } foreach($ilm as $value) { $insert="INSERT INTO dealerguide (ilmissue) VALUES ('$str')"; } mysql_query($insert); Should be $insert="INSERT INTO dealerguide (ilmissue) VALUES ('".implode(",",$_SESSION['details'])."')"; mysql_query($insert); Quote Link to comment https://forums.phpfreaks.com/topic/122347-phpmqsql-problem-data-not-being-inserted/#findComment-631766 Share on other sites More sharing options...
samf_20 Posted September 2, 2008 Author Share Posted September 2, 2008 Thanks for the reply, when I do this it does help. The MySql field that the data is getting inserted into no longer says 'null' it is just blank now. Also i get this error message: Warning: implode() [function.implode]: Invalid arguments passed in C:\Web_Services\sugar\sams_tests\includes\sql.php on line 40 It just sits at the top but doesnt stop the statement functioning? is this saying it cannot read implode or I got to create a function for it? Quote Link to comment https://forums.phpfreaks.com/topic/122347-phpmqsql-problem-data-not-being-inserted/#findComment-631782 Share on other sites More sharing options...
JonnoTheDev Posted September 2, 2008 Share Posted September 2, 2008 This means that $_SESSION['details']; is not an array when it should be. Quote Link to comment https://forums.phpfreaks.com/topic/122347-phpmqsql-problem-data-not-being-inserted/#findComment-631783 Share on other sites More sharing options...
samf_20 Posted September 2, 2008 Author Share Posted September 2, 2008 Ahh makes sense!. Thanks for the help though :] Quote Link to comment https://forums.phpfreaks.com/topic/122347-phpmqsql-problem-data-not-being-inserted/#findComment-631786 Share on other sites More sharing options...
samf_20 Posted September 3, 2008 Author Share Posted September 3, 2008 Bump, still on-going problems. It did just make the mysql field blank and not display null but now mysql doesnt get anything, not even a null on a new line. On all pages I got session_start(); and on the first page I have: $details=$_SESSION['details']; $_SESSION['details']=null; Quote Link to comment https://forums.phpfreaks.com/topic/122347-phpmqsql-problem-data-not-being-inserted/#findComment-632574 Share on other sites More sharing options...
samf_20 Posted September 3, 2008 Author Share Posted September 3, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/122347-phpmqsql-problem-data-not-being-inserted/#findComment-632612 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.