-1

Im working on this searh field and i finally can search from the database using an entered name or national ID no, when i press the find button. But i dont know how to incorporate radio buttons to be submitted to execute a query. can someone help me . my code is below.
what i want is for example if i enter an id card no and click on a radio button as well, so and so id who has completed successfully (yes), needs to be resulted and displayed.
how do i do this?
can there be 2 separate queries or what?
here is the code

html search form

<html>
<strong>SEARCH</strong><br/>
<form style="background-color:#F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;" action="http://localhost/sdc/?q=node/2" method="POST">
<table>
<tr>
<td>Name:</td><td width="300"><input type="text" size="60" name="q"/></td>
</tr>
<tr>
<td>NIC No:</td><td width="150"><input type="text" size="40" name="id"/></td>
</tr>
<tr>
<td>Course:</td>
<td>
<select>
<option>ALL</option>
<option>CTHE</option>
</select>
</td>
</tr>
<tr>
<td>Date of Course:</td><td width="60"><input type="text" size="20" /></td>
</tr>
<tr>
<td>Completed Successfully:</td>
<td width="500">
<input type="radio" name="cs">YES</radio>  <input type="radio" name="cs">NO</radio>  <input type="radio" name="cs" checked>ALL</radio>
</td>
</tr>
<tr>
<td>Current Course Participant:</td>
<td width="500">
<input type="radio" name="pm">YES</radio>  <input type="radio" name="pm">NO</radio>  <input type="radio" name="ccp" checked>ALL</radio>
</td>
</tr>
</table>
<input type="submit" value="FIND" name="find" style="float:right;" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/> 

</form>
 </html>

the php :=
<?php

$q=$_POST['q']; //Get the search text
$id=$_POST['id'];
/*$cs=$_POST['cs'];
echo $cs;*/

if (isset($_POST['find'])) {
$cs = $_POST['cs'];
print $cs;
}

$con = mysql_connect('localhost', 'root', ''); //connect to the database
    if (!$con) //if cannot connect to the database, terminate the process
        {
        die('Could not connect: ' . mysql_error());
        }

    mysql_select_db("sdc_cpds", $con); //Select the databse
    $sql="SELECT * FROM course_participant WHERE name='".$q."' || nic LIKE '$id'"; //Select Query
        //echo $sql;
    $result = mysql_query($sql);//execute the query and get the result
    $num_rows= mysql_num_rows($result); //get the count of the result

    if($num_rows >0)  //If there is a result, display it
    {
        while($row = mysql_fetch_array($result))
        {
            echo $row['name'] ; echo " ";echo $row['nic'] ;echo " "; echo $row['res_address'] ;echo " ";echo $row['contact_no'] ;echo " ";echo $row['email'] ;echo " ";echo $row['gender'] ;echo " ";echo $row['age'] ;echo " ";echo $row['marital_status'] ;echo " ";echo $row['university'] ;echo " ";echo $row['facdept'] ;echo " ";echo $row['course'] ;echo " ";echo $row['course_date'] ;echo " ";echo $row['reg_date'] ;echo " ";echo $row['payments'] ;echo " ";echo $row['completion'] ;
                        echo "<br>";

        }   
    }

       if (isset($_POST['find'])) {

    $cs = $_POST['cs'];

        if ($cs == 'yes') {
            $yes = 'checked';
                        echo "Completed";

        }
        else if ($cs == 'no') {
            $no = 'checked';
                        echo "Current";
        }
          }
       else // If no result found
    {
        echo "No result found!"; //Display the "not found" message
    }

       mysql_close($con); //Close the database connection


      ?>

ive gone thru so many tutorials trying to fix this - please help me out

Edited by Reverend Jim: Fixed formatting

2
Contributors
10
Replies
27
Views
7 Years
Discussion Span
Last Post by rukshilag
0

First try wrapping your codes in code tags when you post. It makes it easier to sort.

You need a value for your radio boxes. The value is returned, not the radio box name.

I could probably tell you more about your code, but as I said before it is too difficult for me to sort.

Edited by Banderson: n/a

0
<html>
<strong>SEARCH</strong><br/>
<form style="background-color:#F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;" action="http://localhost/sdc/?q=node/2" method="POST">
<table>
<tr>
<td>Name:</td><td width="300"><input type="text" size="60" name="q"/></td>
</tr>
<tr>
<td>NIC No:</td><td width="150"><input type="text" size="40" name="id"/></td>
</tr>
<tr>
<td>Course:</td>
<td>
<select>
<option>ALL</option>
<option>CTHE</option>
</select>
</td>
</tr>
<tr>
<td>Date of Course:</td><td width="60"><input type="text" size="20" /></td>
</tr>
<tr>
<td>Completed Successfully:</td>
<td width="500">
<input type="radio" name="cs">YES</radio> <input type="radio" name="cs">NO</radio> <input type="radio" name="cs" checked>ALL</radio>
</td>
</tr>
<tr>
<td>Current Course Participant:</td>
<td width="500">
<input type="radio" name="pm">YES</radio> <input type="radio" name="pm">NO</radio> <input type="radio" name="ccp" checked>ALL</radio>
</td>
</tr>
</table>
<input type="submit" value="FIND" name="find" style="float:right;" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/>

</form>
</html>

the php is

<?php

$q=$_POST['q']; //Get the search text
$id=$_POST['id'];
/*$cs=$_POST['cs'];
echo $cs;*/

if (isset($_POST['find'])) {
$cs = $_POST['cs'];
print $cs;
}

$con = mysql_connect('localhost', 'root', ''); //connect to the database
if (!$con) //if cannot connect to the database, terminate the process
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("sdc_cpds", $con); //Select the databse
$sql="SELECT * FROM course_participant WHERE name='".$q."' || nic LIKE '$id'"; //Select Query
//echo $sql;
$result = mysql_query($sql);//execute the query and get the result
$num_rows= mysql_num_rows($result); //get the count of the result

if($num_rows >0) //If there is a result, display it
{
while($row = mysql_fetch_array($result))
{
echo $row['name'] ; echo " ";echo $row['nic'] ;echo " "; echo $row['res_address'] ;echo " ";echo $row['contact_no'] ;echo " ";echo $row['email'] ;echo " ";echo $row['gender'] ;echo " ";echo $row['age'] ;echo " ";echo $row['marital_status'] ;echo " ";echo $row['university'] ;echo " ";echo $row['facdept'] ;echo " ";echo $row['course'] ;echo " ";echo $row['course_date'] ;echo " ";echo $row['reg_date'] ;echo " ";echo $row['payments'] ;echo " ";echo $row['completion'] ;
echo "<br>";

}
}

if (isset($_POST['find'])) {

$cs = $_POST['cs'];

if ($cs == 'yes') {
$yes = 'checked';
echo "Completed";

}
else if ($cs == 'no') {
$no = 'checked';
echo "Current";
}
}
else // If no result found
{
echo "No result found!"; //Display the "not found" message
}

mysql_close($con); //Close the database connection


?>

there you go - please help..
when this is executed with any of the radio buttons are clicked it simply outputs "on" when i want it to show if its yes or no

0

Try this first. Just change this code, leave your PHP intact for now. Be sure to save backups while testing.

<html>
<strong>SEARCH</strong><br/>
<form style="background-color:#F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;" action="http://localhost/sdc/?q=node/2" method="POST">
<table>
<tr>
<td>Name:</td><td width="300"><input type="text" size="60" name="q"/></td>
</tr>
<tr>
<td>NIC No:</td><td width="150"><input type="text" size="40" name="id"/></td>
</tr>
<tr>
<td>Course:</td>
<td>
<select>
<option>ALL</option>
<option>CTHE</option>
</select>
</td>
</tr>
<tr>
<td>Date of Course:</td><td width="60"><input type="text" size="20" /></td>
</tr>
<tr>
<td>Completed Successfully:</td>
<td width="500">
<input type="radio" name="cs" value="yes">YES</radio> <input type="radio" name="cs" value="no">NO</radio> <input type="radio" name="cs" value="all is checked" checked>ALL</radio>
</td>
</tr>
<tr>
<td>Current Course Participant:</td>
<td width="500">
<input type="radio" name="pm">YES</radio> <input type="radio" name="pm">NO</radio> <input type="radio" name="ccp" checked>ALL</radio>
</td>
</tr>
</table>
<input type="submit" value="FIND" name="find" style="float:right;" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/>

</form>
</html>
-1

ah it dispalys yes now when i click radio button yes, but what i want is for the completed successflully student to list down when i click yes along with a given ID no or name, u can see my query right?
should there be another query?

0

Remember to save a backup. Try this PHP code

<?php

$q=$_POST['q']; //Get the search text
$id=$_POST['id'];
/*$cs=$_POST['cs'];
echo $cs;*/

if (isset($_POST['find'])) {
$cs = $_POST['cs'];
print $cs;
}

$con = mysql_connect('localhost', 'root', ''); //connect to the database
if (!$con) //if cannot connect to the database, terminate the process
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("sdc_cpds", $con); //Select the databse
$sql="SELECT * FROM course_participant WHERE name='".$q."' || nic LIKE '$id'"; //Select Query
//echo $sql;
$result = mysql_query($sql);//execute the query and get the result
$num_rows= mysql_num_rows($result); //get the count of the result

if($num_rows >0) //If there is a result, display it
{
while($row = mysql_fetch_array($result))
{
echo $row['name']; echo " ";echo $row['nic'] ;echo " "; echo $row['res_address'] ;echo " ";echo $row['contact_no'] ;echo " ";echo $row['email'] ;echo " ";echo $row['gender'] ;echo " ";echo $row['age'] ;echo " ";echo $row['marital_status'] ;echo " ";echo $row['university'] ;echo " ";echo $row['facdept'] ;echo " ";echo $row['course'] ;echo " ";echo $row['course_date'] ;echo " ";echo $row['reg_date'] ;echo " ";echo $row['payments'] ;echo " ";echo $row['completion'] ;
echo "<br>";

}
}

if (isset($_POST['find'])) {

$cs = $_POST['cs'];

if ($cs == 'yes') {
$yes = 'checked';
//echo 'Completed';
echo "The Test Was Completed <br />Student Id: ". $row['nic']."<br />Student Name: ". $row['name'];


}
else if ($cs == 'no') {
$no = 'checked';
echo "Current";
}
}
else // If no result found
{
echo "No result found!"; //Display the "not found" message
}

mysql_close($con); //Close the database connection


?>
-1

this is the result i get when i enter the nic and click "yes" radio button for completed successfully - what i shud get is that record i have entered but it simply says this :-

yesThe Test Was Completed
Student Id:
Student Name:

0

Save a backup! I edited your code substantially! This should give you the results you are requesting.

<?php

if (isset($_POST['find'])) {
$cs = $_POST['cs'];
$q=$_POST['q']; //Get the search text
$id=$_POST['id'];
//print $cs;
}

$con = mysql_connect('localhost', 'root', ''); //connect to the database
if (!$con) //if cannot connect to the database, terminate the process
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("sdc_cpds", $con); //Select the databse
$sql="SELECT * FROM course_participant WHERE name='".$q."' || nic LIKE '$id'"; //Select Query
$result = mysql_query($sql);//execute the query and get the result
$num_rows= mysql_num_rows($result); //get the count of the result

if($num_rows >0) //If there is a result, display it
{
while($row = mysql_fetch_array($result))
{
echo $row['name']; echo " ";echo $row['nic'] ;echo " "; echo $row['res_address'] ;echo " ";echo $row['contact_no'] ;echo " ";echo $row['email'] ;echo " ";echo $row['gender'] ;echo " ";echo $row['age'] ;echo " ";echo $row['marital_status'] ;echo " ";echo $row['university'] ;echo " ";echo $row['facdept'] ;echo " ";echo $row['course'] ;echo " ";echo $row['course_date'] ;echo " ";echo $row['reg_date'] ;echo " ";echo $row['payments'] ;echo " ";echo $row['completion'] ;
echo "<br>";



$cs = $_POST['cs'];

if ($cs == 'yes') {
$yes = 'checked';
//echo 'Completed';
echo "The Test Was Completed <br />Student Id: ". $row['nic']."<br />Student Name: ". $row['name'];


}
else if ($cs == 'no') {
$no = 'checked';
echo "Current";
}

else // If no result found
{
echo "No result found!"; //Display the "not found" message
}

mysql_close($con); //Close the database connection



}
}

?>
-1

it doesnt seem to display the name and id but only says yes. btw the table has a field called completion which says yes or no, so when one of the radio buttons in the completed successfully is clicked it should correspond with the table field completion and there on display results along with the nic given in a text field

0

it doesnt seem to display the name and id but only says yes. btw the table has a field called completion which says yes or no, so when one of the radio buttons in the completed successfully is clicked it should correspond with the table field completion and there on display results along with the nic given in a text field

That's strange because I ran this code on localhost and it worked for me. I don't think this has anything to do with it, but I am running PHP version : 5.3.0.

I am slightly busy with another project right now. If you do not get anymore replies or still don't have it working after a while, send me a message via skype : ncprogramming and I will try to help you further.

I felt for sure this was going to work for you. :-O

0

ok so the code is okay - but i cant get the results to display in a table as the html table shown - please help with this - here is the code again - i also want each displayed result to show with a radio button so a required result can be selected and sent to the edit page

<html>
<head>
<style type="text/css">
.up {
float:right; 
background-color:#1b5b88;
border:2px solid;
padding:4px;
color:white;
}

.over{
float:right; 
background-color:#1b5b88;
border:4px solid;
border-color:#CEE3F6;
padding:2px;
color:white;
}

</style>
</head>

<strong>SEARCH</strong><br/>
<form style="background-color:#F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;" action="http://localhost/sdc/?q=node/2" method="POST">
<table>
<tr>
<td>Name:</td><td width="300"><input type="text" size="60" name="q"/></td>
</tr>
<tr>
<td>NIC No:</td><td width="150"><input type="text" size="40" name="id"/></td>
</tr>
<tr>
<td>Course:</td>
<td>
<select>
<option>ALL</option>
<option>CTHE</option>
</select>
</td>
</tr>
<tr>
<td>Date of Course:</td><td width="60"><input type="text" size="20" /></td>
</tr>
<tr>
<td>Completed Successfully:</td>
<td width="500">
<input type="radio" name="cs" value="yes">YES</radio>  
<input type="radio" name="cs" value="no">NO</radio>  
<input type="radio" name="cs" value="all" checked>ALL</radio>
</td>
</tr>
<tr>
<td>Current Course Participant:</td>
<td width="500">
<input type="radio" name="pm" value="current">YES</radio>  
<input type="radio" name="pm" value="past">NO</radio>  
<input type="radio" name="pm" value="allpart" checked>ALL</radio>
</td>
</tr>
</table>
<input type="submit" value="FIND" name="find" style="float:right;" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/> 

</form>


<form action="http://localhost/sdc/?q=node/3" method="post">
<div style="width:750px; height:250px; overflow:auto; border:1px solid; border-color:#084B8A; padding:10px;">
<table border="3">
<tr style="background-color:#A9D0F5">
<th width="100">Course Participant ID</td>
<th width="500">Name</th>
<th width="350">NIC</th>
<th width="250">Contact No</th>
<th width="250">Email</th>
<th width="150">Gender</th>
<th width="150">Age</th>
<th width="200">Marital Status</th>
<th width="300">University</th>
<th width="300">Faculty/Department</th>
<th width="300">Course</th>
<th width="150">Payments</th>
<th width="150">Completion</th>
</tr>
<tr style="background-color:#CEE3F6">
<td>CP001</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
<tr>
<td>CP002</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr style="background-color:#CEE3F6">
<td>CP003</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td>CP004</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr style="background-color:#CEE3F6">
<td>CP005</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td>CP006</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr style="background-color:#CEE3F6">
<td>CP007</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td>CP008</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr style="background-color:#CEE3F6">
<td>CP009</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
</table>
</div>
<input type="submit" value="EDIT" class="up" style="float:right;" onmouseover="this.className='over'" onmouseout="this.className='up'"/>
<br/>
</html>


<?php

if (isset($_POST['find'])) {
$cs = $_POST['cs'];
$q=$_POST['q']; //Get the search text
$id=$_POST['id'];
//print $cs;
}

$con = mysql_connect('localhost', 'root', ''); //connect to the database
if (!$con) //if cannot connect to the database, terminate the process
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("sdc_cpds", $con); //Select the databse
$sql="SELECT * FROM course_participant WHERE name='".$q."' || nic LIKE '$id'"; //Select Query
$result = mysql_query($sql);//execute the query and get the result
$num_rows= mysql_num_rows($result); //get the count of the result

if($num_rows >0) //If there is a result, display it
{
while($row = mysql_fetch_array($result))
{
echo $row['name']; echo " ";echo $row['nic'] ;echo " "; echo $row['res_address'] ;echo " ";echo $row['contact_no'] ;echo " ";echo $row['email'] ;echo " ";echo $row['gender'] ;echo " ";echo $row['age'] ;echo " ";echo $row['marital_status'] ;echo " ";echo $row['university'] ;echo " ";echo $row['facdept'] ;echo " ";echo $row['course'] ;echo " ";echo $row['course_date'] ;echo " ";echo $row['reg_date'] ;echo " ";echo $row['payments'] ;echo " ";echo $row['completion'] ;
echo "<br>";

}
echo "<table border=1>";
		while ($line = mysql_num($result, MYSQL_ASSOC)) {
			
			echo "<tr>";
			
			echo "<td>";
				echo $line["name"];
			echo "</td>";
			echo "<td>";
				echo $line["nic"];
			echo "</td>";
			echo "<td>";
				echo $line["res_address"];
			echo "</td>";
			echo "<td>";
				echo $line["email"];
			echo "</td>";	
			
			echo "<td>";
				echo "<td><A href=\"http://localhost/sdc/?q=node/3?name={$line["name"]}\">Edit</A></td>";		
			echo "</td>";
				
			echo "</tr>";		
		}
		echo "</table>";

}



extract($_POST);

if($q != '') {
	if($id != '') {
		$sql = "select * from course_participant where name = '$q' and nic = '$id'";
	}else {
		$sql = "select * from course_participant where name = '$q'";
	}
}else {
	if($id != '') {
		$sql = "select * from course_participant where nic = '$id'";
	}else if($sql<0){
		// error !!!
		$sql = false;
                echo "No Result Found!";
	}
}


if($sql) {
	$sql .= " and completed = '$cs'";
	
	// execution goes here!!!
} else if($sql) {

        $sql .=" and completed = '$pm'";

}

else if($num_rows<0)// If no result found
{
echo "No result found!"; //Display the "not found" message
}

mysql_close($con); //Close the database connection




?>

Edited by rukshilag: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.