Hi - here is my code - it is for searching
what i have done as u can see is - for every results the CP_ID is hyperlinked and opens up to the edit page. but no value gets passed. what i want is when a search result appears i click on CP_ID to open it up in the edit page and the nic of that selected record shud be passed as well to the edit page instead of it just opening when a CP_ID is clicked.

search code

<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/>
<div>
<form style="background-color:#F2F2F2; border:1px solid; border-color:#084B8A; width:750px;" 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>
<option>ATHE</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>  
</td>
</tr>
<tr>
<td>Current Course Participant:</td>
<td width="500">
<input type="radio" name="cst" value="yes">YES</radio>  
<input type="radio" name="cst" value="no">NO</radio>  
</td>
</tr>
</table>
</div>
<input type="submit" value="FIND" name="find" style="float:right;" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/> 

<h3>*Click on a Course Participant ID, if EDIT is required. <br></h3>
</html>

<?php
/*
if (isset($_POST['find'])) {
$cs = $_POST['cs'];
$current = $_POST['cst'];
$q=$_POST['q']; 
$id=$_POST['id']; 
}*/

session_start();
if (isset($_POST['find'])) {
$cs = $_POST['cs'];
$current = $_POST['cst'];
$q=$_POST['q'];
$id=$_POST['id'];
$_SESSION['nic'] = $id;
}


$con = mysql_connect('localhost', 'root', ''); 
if (!$con) 
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("sdc_cpds", $con); 

extract($_POST);

if($q != '') {
	if($id != '') {
		$sql = "select * from course_participant where name LIKE '%$q%' and nic = '$id'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}else {
		$sql = "select * from course_participant where name LIKE '%$q%'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}
}else {
	if($id != '') {
		$sql = "select * from course_participant where nic = '$id'";
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
	}else if($sql<0){
		// error !!!
		$sql = false;
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
                echo "No Result Found!";
	}
}
if($cs!=''){
$sql = "select * from course_participant where completion LIKE '%$cs%' and name LIKE '%$q%'";
$result = mysql_query($sql);
$num_rows= mysql_num_rows($result);
}else if($sql<0){
		// error !!!
		$sql = false;
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
                echo "No Result Found!";
}
if($cst!=''){
$sql = "select * from course_participant where current LIKE '%$cst%' and name LIKE '%$q%'";
$result = mysql_query($sql);
$num_rows= mysql_num_rows($result);
}else if($sql<0){
		// error !!!
		$sql = false;
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
                echo "No Result Found!";
}


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

        $sql .=" and current = '$current'";

}


if($num_rows >0) {

echo "<table border='3'>";
echo "<tr style='background-color:#A9D0F5'> <th width='100'>CP_ID</th><th width='200'>Name</th><th width='350'>NIC</th><th width='750'>Address</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'>Fac/Dept</th><th width='300'>Course</th><th width='150'>Course Date</th><th width='150'>Reg. Date</th><th width='150'>Payments</th><th width='150'>Completion</th><th width='150'>Current</th> </tr>";

while($row = mysql_fetch_array( $result )) {
echo "<form name='tableform' method='get'>";
echo "<tr style='background-color:#CEE3F6'>"; 
//echo "<a href='http://localhost/sdc/?q=node/3'>EDIT";
echo "<td>";echo "<a href='http://localhost/sdc/?q=node/3'>";echo $row['CP_ID'];echo "</td>"; 
echo "<td>";echo $row['name'];echo "</td>"; 
 echo "<td>";echo $row['nic'];echo "</td>"; 
 echo "<td>";echo $row['address'];echo "</td>"; 
 echo "<td>";echo $row['contact_no'];echo "</td>"; 
 echo "<td>";echo $row['email'];echo "</td>"; 
 echo "<td>";echo $row['gender'];echo "</td>"; 
 echo "<td>";echo $row['age'];echo "</td>"; 
 echo "<td>";echo $row['marital_status'];echo "</td>"; 
 echo "<td>";echo $row['university'];echo "</td>"; 
 echo "<td>";echo $row['facdept'];echo "</td>"; 
 echo "<td>";echo $row['course'];echo "</td>"; 
 echo "<td>";echo $row['course_date'];echo "</td>"; 
 echo "<td>";echo $row['reg_date'];echo "</td>"; 
 echo "<td>";echo $row['payments'];echo "</td>"; 
 echo "<td>";echo $row['completion'];echo "</td>"; 
 echo "<td>";echo $row['current'];echo "</td>"; 
echo "</tr>";
echo "<br>";

} 
echo "</table>";

}

else if (isset($_POST['find'])) {
 echo "No Result Found";
}


mysql_close($con); 


?>

edit page

<strong>PERSONAL DATA</strong>
<form style="background-color:#
F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;" name="f1" method="get" action="http://localhost/sdc/?q=node/2"> 
<table>
<tr>
<td>Name:</td><td width="500"><input type="text" size="60" value=></td>
</tr>
<tr>
<td>Residential Address:</td><td width="300"><input type="text" size="60"></td>
</tr>
<tr>
<td></td><td><input type="text" size="60"/></td>
</tr>
<tr>
<td>NIC:</td><td width="300"><input type="text" size="9" value=<?php echo $q ?>>V</td>
</tr>
<tr>
<td>Contact No.:</td><td width="300"><input type="text" size="12"/></td>
</tr>
<tr>
<td>e-mail Address:</td><td width="300"><input type="text" size="12"/></td>
</tr>
<tr>
<td>Gender:</td><td width="300">
<input type="radio" name="sex">MALE</radio>  <input type="radio" name="sex">FEMALE</radio>
</td>
</tr>
<tr>
<td>Age:</td><td width="300"><input type="text" size="2"/></td>
</tr>
<tr>
<td>Marital Status:</td>
<td width="300">
<input type="radio" name="mar">MARRIED</radio>  <input type="radio" name="mar">UNMARRIED</radio>
</td>
</tr>
<tr>
<td>University:</td>
<td>
<select>
<option>COLOMBO</option>
<option>PERADENIYA</option>
</select>
</td>
</tr>
<tr>
<td>Faculty/Dept:</td>
<td>
<select>
<option>UCSC</option>
<option>SCIENCE</option>
</select>
</td>
</tr>
</table>
</form>
<br/>

Recommended Answers

All 3 Replies

Change line no 163 as given below

echo "<td>";echo "<a href='http://localhost/sdc/?q=node/3&CP_ID={$row['CP_ID']}'>";echo $row['CP_ID'];echo "</td>";

Now in your edit page you will get value of clicked CP_ID in
$_REQUEST variable.

where do i place that line???

Replace whole line no 163 of your posted code, with the code line posted by me on search page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.