rukshilag 0 Junior Poster

So here is my search query set

/all possible input combinations

//name and id combinations

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){
		$sql = false;
                $result = mysql_query($sql);
                $num_rows= mysql_num_rows($result);
                echo "No Result Found!";
	}*/
}


//name and completed successfully
if($cs=='yes'){
     if($q!=''){
       $sql = "select * from past_participant where completion LIKE '%$cs%' and name LIKE '%$q%'";
          $result = mysql_query($sql);
          $num_rows= mysql_num_rows($result);
    }else if($cs=='current'){
       $sql = "select * from course_participant where completion LIKE '%$cs%' and name LIKE '%$q%'";
          $result = mysql_query($sql);
          $num_rows= mysql_num_rows($result);
    }
}





//if only course is selected
if($course!='') {
    $sql = "SELECT * FROM past_participant WHERE course='$course' UNION SELECT * FROM course_participant WHERE course='$course'";

         $result = mysql_query($sql);
         $num_rows= mysql_num_rows($result);
    }


//another problem query - all records of both tables
if($course=='all') {
    $sql = "SELECT * FROM past_participant UNION SELECT * FROM course_participant";

         $result = mysql_query($sql);
         $num_rows= mysql_num_rows($result);
}

//if date of course and course is selected and completion (yes/no/current)
if($cd!=''){
 if($course!=''){
   if($cs=='yes') {
    $sql="select * from past_participant where course_date='$cd'";
      $result = mysql_query($sql);
      $num_rows= mysql_num_rows($result);
    }else if($cs=='no') {
      $sql="select * from course_participant where course_date='$cd' and course LIKE '%$course%'";
      $result = mysql_query($sql);
      $num_rows= mysql_num_rows($result);
     }else if($cs=='current') {
      $sql="select * from course_participant where course_date='$cd' and course LIKE '%$course%'";
      $result = mysql_query($sql);
      $num_rows= mysql_num_rows($result);
    }
   }
  }


//only completed successfully
if($cs =='yes') {
       $sql = "select * from past_participant WHERE completion='$cs'";
       $result = mysql_query($sql);
       $num_rows= mysql_num_rows($result);
} //if no is selected it should compare with both tables
else if($cs =='no') {
       $sql = "select * from past_participant WHERE completion='$cs'";
       $result = mysql_query($sql);
       $num_rows= mysql_num_rows($result);
}else if($cs=='current') {
       $sql = "select * from course_participant WHERE completion='$cs'";
       $result = mysql_query($sql);
       $num_rows= mysql_num_rows($result);

}

//course and completion - problem query
if($course!='blank'){
if($cs=='yes'){
    $sql = "select * FROM past_participant WHERE course='$course' and completion='$cs'";
         $result = mysql_query($sql);
         $num_rows= mysql_num_rows($result);
}

else if($cs=='current'){
  $sql = "select * FROM course_participant WHERE course='$course' and completion='$cs'";
         $result = mysql_query($sql);
         $num_rows= mysql_num_rows($result);
}
else if($cs=='no'){
  $sql = "select * FROM past_participant WHERE course='$course' and completion='$cs'";
         $result = mysql_query($sql);
         $num_rows= mysql_num_rows($result);
}
}

when i run that very 1st query
searching by name - on phpmyadmin i get this error
Error

SQL query: Documentation

if( $q != '' ) {if( $id != '' ) {$sql = "select * from course_participant where name LIKE '%$q%' and nic='$id'";

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if($q != '') {
if($id != '') {
$sql = "select * from course_participant whe' at line 1

please help

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.