xxreenaxx1 Posted February 19, 2011 Share Posted February 19, 2011 I have created a query to show the subject name as a drop down box now I would like to you use value to compare what module available in the database. For now I can disaplyed all the module that is avilable for all the subject. But i would like to use the drop down box to gather which subject they have chosend then use this information to gather the module $query=("SELECT Tes_Name FROM User u, Subject s, Test t WHERE u.Use_ID = '{$_SESSION['ID']}' AND s.Sub_ID=t.Sub_ID "); <Html> <?php session_start(); $Value1 = mysql_real_escape_string(trim($_POST['myselect'])); $_SESSION['myselect'] = $Value1; //echo $Value1; include '../Database/connection.php'; ?> <body> <form action="Previousq_Module2.php" method="post"> <?PHP include '../Database/Module_Exsit.php'; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=select>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Tes_ID'].">".$row['Tes_Name']."</OPTION>"; } echo "</select>"; ?> <input type="submit" value="submit"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/ Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 And where are you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176701 Share on other sites More sharing options...
xxreenaxx1 Posted February 19, 2011 Author Share Posted February 19, 2011 I need to compare with the subjejct chosen. For now its showing all the module that the staff provides ,since I am using $_SESSION['ID'] to get the staff details. Now I want to use $_SESSION['myselect'] to get the subject which has been submited through the drop box. But when I try to do this, it shows me nothing.. Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176709 Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 I see where you assign the value to the session var, but I don't see where you ever actually use it. Are you able to echo it? Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176713 Share on other sites More sharing options...
Skepsis Posted February 19, 2011 Share Posted February 19, 2011 Does the query return any results? It looks like you are using two separt tables but not using the JOIN option in your query, have you ran a dump on your query to see if rows were being brought back properly? you can add $dump[] = $row; print_r($dump); under while($row=mysql_fetch_array($result)){ from that point we can see where to go. Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176718 Share on other sites More sharing options...
xxreenaxx1 Posted February 19, 2011 Author Share Posted February 19, 2011 Yeh when I echo the session, it says Array and when i tried to run the query in mysql it worked. I tired to work with the session that was collected from myselect but it gives me nothing. $query=("SELECT Tes_Name FROM User u, Subject s, Test t WHERE u.Use_ID = '{$_SESSION['ID']}' AND t.Sub_ID = '{$_SESSION['myselect']}' AND t.Sub_ID = s.Sub_ID "); Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176754 Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 Echo the query and see if it contains the values you'd expect it to contain. Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176757 Share on other sites More sharing options...
xxreenaxx1 Posted February 19, 2011 Author Share Posted February 19, 2011 Subject Id is NOT showing. So I am assuming something wrong with my subject drop box <Html> <?php session_start(); include '../Database/connection.php'; ?> <body> <form action="Previousq_Module1.php" method="post"> <?PHP include '../Database/subject_exsitsql.php'; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=myselect>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Sub_ID'].">".$row['Sub_Name']."</OPTION>"; } echo "</select>"; ?> This is used as session on the next page which I HAVE ALREADY SHOWN ON MY FIRST POST. Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176767 Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 The name= and value= attributes aren't valid markup without quotes, and upper case values in tags may not be handled properly if it's an XHTML doctype. Oh, and there's no query string in that code, just the $query variable in mysql_query($query) . . . echo '<select name="myselect">'; while( $row=mysql_fetch_assoc($result) ) { echo "<option value=\"{$row['Sub_ID']}\">{$row['Sub_Name']}</option>"; } echo "</select>"; Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176773 Share on other sites More sharing options...
xxreenaxx1 Posted February 19, 2011 Author Share Posted February 19, 2011 My Subject ID wont show These are my code. <Html> <?php session_start(); include '../Database/connection.php'; ?> <body> <form action="Previousq_Module1.php" method="post"> <?PHP include '../Database/subject_exsitsql.php'; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo '<select name="mselect">'; while( $row=mysql_fetch_assoc($result) ) { echo "<option value=\"{$row['Sub_ID']}\">{$row['Sub_Name']}</option>"; } echo "</select>"; ?> <input type="submit" value="submit"/> </form> </body> </html> This is to get the subject The query for this is <?PHP $query=("SELECT Sub_Name FROM User u, Subject s, Test t WHERE u.Use_ID = '{$_SESSION['ID']}' AND s.Sub_ID=t.Sub_ID AND t.Sub_ID= t.Tes_ID "); ?> This form then send to the one shown below <html> <body> <?php session_start(); include '../Database/connection.php'; $Value1 = mysql_real_escape_string(trim($_POST['mselect'])); $_SESSION['mselect'] = $Value1; echo $Value1; ?> <form action="Previousq_Module2.php" method="post"> <?PHP include '../Database/Module_Exsit.php'; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=select>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Tes_ID'].">".$row['Tes_Name']."</OPTION>"; } echo "</select>"; ?> <input type="submit" value="submit"/> </form> This drop down box shows me nothing. the query for this is <?PHP $query="(SELECT Tes_Name FROM User u, Subject s, Test t WHERE u.Use_ID = '{$_SESSION['ID']}' AND s.Sub_ID = '{$_SESSION['mselect']}' AND s.Sub_ID = t.Sub_ID ) "; echo $query; $query1 = mysql_query($query); ?> Now where is the fault. I seriously cant fix this. I dont know whats wrong with this. help me out The echo gives me (SELECT Tes_Name FROM User u, Subject s, Test t WHERE u.Use_ID = '3' AND s.Sub_ID = '' AND s.Sub_ID = t.Sub_ID ) Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176807 Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 Add the line I've indicated in the code, and post the output it generates when you reach that point in the form submission process. <html> <body> <?php session_start(); include '../Database/connection.php'; echo '<pre>'; print_r($_POST); echo '</pre>'; // <--- ADD THIS $Value1 = mysql_real_escape_string(trim($_POST['mselect'])); $_SESSION['mselect'] = $Value1; echo $Value1; Quote Link to comment https://forums.phpfreaks.com/topic/228190-get-values-for-the-subject-that-has-been-selected/#findComment-1176808 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.