Jump to content

Recommended Posts

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>

 

 

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..

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.

 

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


");

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.

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>";

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 )

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.