thara Posted April 28, 2012 Share Posted April 28, 2012 Hello Everyone.. Im a programer in php with little experience. I have a form with 3 pages. 1st page display categories which come from category table. then user can select 1 or upto 3 category there. Then 2nd page display that selected categories and need to display relevant subject to that categories. In second page I use radio button for selected categories to keep a one category as a main category. each categories' subjects display with check boxes. In there too, user can select 1 or 3 more subject in to a particular category. In third form page, that my problem was encounter, there I need to print out selected category and their subjects in a table. first two pages are no problem for me and third form I have a problem in how to get categories and their subjects and they print as apiece in the page. like this category1 | subject1, subject2, subject3 category2 | subject1, subject2, subject3, subject and so forth. This same to my first form page $q = 'SELECT * FROM category ORDER BY category_id'; $r = mysqli_query( $dbc, $q); $c = 0; $i = 0; echo '<form action="subjects.php" method="post">'; echo '<table class="form_table" ><tr>'; while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="category[]" value="' . $row['category_id'] . '" /> ' . $row['category_name'] . '</td>'; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; ?> In second page 'subjects.php' I use if ( isset($_POST['submitted1']) && isset($_POST['category']) && sizeof( $_POST['category']) == 3 ) { $_SESSION['category'] = $_POST['category']; print_r ( $_SESSION['category']); $q = 'SELECT * FROM category ORDER BY category_id'; $r = mysqli_query( $dbc, $q); while($_SESSION = mysqli_fetch_array( $r, MYSQLI_ASSOC )){ foreach( $_POST['category'] as $value ) { if ( $value == $_SESSION['category_id']) { $q = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = {$_SESSION['category_id']}"; $r1 = mysqli_query( $dbc, $q); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($_SESSION = mysqli_fetch_array( $r1, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="subject[]" value="' . $_SESSION['subject_id'] . '" /> ' . $_SESSION['subjects'] . '</td>'; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } } } } Those two pages working properly. In third page that my problem page I tried something like this , but its not working. value come from subject.php page. if ( ( isset($_POST['submitted2'])) && ( isset($_SESSION['category'])) && (isset( $_SESSION['subjects'])) && sizeof( $_SESSION['category']) == 1) { //$_SESSION['category'] = $_POST['category']; print_r ( $_SESSION['category']); echo 'good'; } elseif ( ( isset($_POST['submitted2'])) && ( isset($_SESSION['category'])) && (isset( $_POST['main_category'] ))) { print_r ( $_SESSION ); echo 'very good'; } So can any body tell me where is my mistake and help me fix this problem. any help greatly appreciated. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/ Share on other sites More sharing options...
ManiacDan Posted April 28, 2012 Share Posted April 28, 2012 Define "not working." What output are you getting, and what are you expecting? Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/#findComment-1341418 Share on other sites More sharing options...
El Chupacodra Posted April 28, 2012 Share Posted April 28, 2012 Unless I missed it there is no call to session_start() anywhere. You need that to have session variables set and read. Put it early, definitely before any HTML is output - but in some configurations you need to have it before anything else. Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/#findComment-1341438 Share on other sites More sharing options...
thara Posted April 29, 2012 Author Share Posted April 29, 2012 I am expecting to print out selected categories and its selected subjects. here I have attached my expecting result in the third form. Actually I need know what are the selected categories and their subjects from 2nd page and those values should bring to my 3rd form and display it. Every page I have started the sessions. any help greatly appreciated. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/#findComment-1341475 Share on other sites More sharing options...
thara Posted April 29, 2012 Author Share Posted April 29, 2012 this attachment shows how my second page is going and how users can select 1 category as main and their subjects. please note: users can select subjects even if it is not the main category. those category come from my first page. Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/#findComment-1341478 Share on other sites More sharing options...
thara Posted May 11, 2012 Author Share Posted May 11, 2012 page1.php page ok it display every category from my database. echo '<td width="50%"><input type="checkbox" name="category[]" value="' . $row['category_id'] . '" /> ' . $row['category_name'] . '</td>'; In my second page I need to display selected categories from 1st page and relevant subjects to that categories. eg: cat1 | sub1, sub2, sub3 cat2 | sub1, sub2, sub3, cat3 | sub1, sub4, sub5 and so on. every category has some subjects and all of those subjects should be display in my second page as category wise. subject also come from my subject table. category_subject table also available to make the relationship between every category and subject. In second page also working as I am expecting. above I have posted my second page coding. But my problem is 3rd page. In second page users can select 3 more subjects to 1 category. assume there is 3 category users can select 9 subjects. so my problem is how I bring those category and their subjects from 2nd page to my 3rd page. actually I am very confusing here and I try to do this for days. unfortunately still I cant get my expecting results. I waiting for any comments and those are greatly appreciated. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/#findComment-1344672 Share on other sites More sharing options...
thara Posted May 11, 2012 Author Share Posted May 11, 2012 can anybody help me plz.....????? thank you.. Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/#findComment-1344682 Share on other sites More sharing options...
Drummin Posted May 11, 2012 Share Posted May 11, 2012 Ya, you can't set or modify sessions after anything is sent to the browser. You should have 1. Processing of posts/set sessions/ any header redirect tags header() tags etc 2. html head and body tags 3. visual content/forms etc. 4. close out your page On your pages I don't see item 2, but I do see item 1 and item 3 mixed together. Work on restructuring things. Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/#findComment-1344701 Share on other sites More sharing options...
thara Posted May 12, 2012 Author Share Posted May 12, 2012 Thank you very much for your answers. ... this is a example of what I'm try to do... http://www.myprivatetutor.com/tutor_registration.php actually I'm trying to create such a registration form to my project. category table, subject table and category_subject table I have created. thanks for any comments. Quote Link to comment https://forums.phpfreaks.com/topic/261759-how-i-get-the-values-to-my-third-page-form/#findComment-1344913 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.