0

I got a database which contain data of jobseeker and employer. I create a form to search for jobseeker . The form contain textform and checkboxes . The problem is after i fill in any field and submit the result is not shown . Is there anything wrong with my code ?

<?php

    session_start();

    require_once "inc/db.php";
    require_once "inc/tarikh.php";
    require_once "inc/config.php";
    require_once "inc/template.php";


    if($_SESSION['sid'] == ""){
        auth(array(1,2));
    }

    # pagination setting start
    if($_REQUEST['start'] == ''){
        $start = 0;
    }
    else{
        $start = $_REQUEST['start'];
    }
    if($_REQUEST['page'] == ''){
        $page = 1;
    }
    else{
        $page = $_REQUEST['page'];
    }

    $senarai_kp = array();

    # pagination setting end


    // check if the form was submitted
    if(isset($_POST['btn_cari'])) {

        $qry  = 'SELECT * FROM jobseeker AS js ';
        $qry .= 'FULL OUTER JOIN jobseeker_pendidikan AS jp ON js.no_kp=jp.no_kp ';
        $qry .= 'FULL OUTER JOIN jobseeker_pengalaman AS jpn ON js.no_kp=jpn.no_kp ';

        $operator = 'WHERE';

        // check if name / id was submited to be searched for
        // id and name is on one textform
            if(isset($_POST['txt_nama']) and $_POST['txt_nama'] != '') {

            $qry .= "$operator nama LIKE '".addslashes($_POST['txt_nama'])."' 
                    OR no_kp LIKE '".addslashes($_POST['txt_nama'])."' ";

            $operator = 'AND';
        }

        // check if disctrict were submited to be searched for
            if(isset($_POST['txt_mukim']) and $_POST['txt_mukim'] != '') {

            // remove spaces that might follow commas
            $mukim = str_replace(', ', ',', $_POST['txt_mukim']);

            $mukim_array = explode(',', $mukim);

            foreach($mukim_array as $one_mukim) {

                $qry .= "$operator daerah LIKE '$one_mukim' ";

                // change the operator from WHERE to AND
                $operator = 'AND';
            }
        }

        // check if sex was submited to be searched for
            if(isset(($_POST['chk_jantina_lelaki'] == 'null') && ($_POST['chk_jantina_perempuan'] == 'perempuan'))){


             $qry .= "$operator jantina='perempuan' ";
             elseif(($_POST['chk_jantina_lelaki'] == 'lelaki') && ($_POST['chk_jantina_perempuan'] == 'null')){
                $qry .="$operator jantian='lelaki' ";
                }

            $operator = 'AND';
        }

        // check if age was submitted to be search for
        // checkbox form
            if(isset(($_POST['txt_julat_umur'] != '') && ($_POST['txt_julat_umur2'] == ''))) {

                $qry .= "$operator (YEAR(NOW()) - tahun_lahir) > '".addslashes($_POST['txt_julat_umur'])."'";
                )
                elseif(($_POST['txt_julat_umur'] != '') && ($_POST['txt_julat_umur2'] == '')){
                $qry .= "$operator (YEAR(NOW()) - tahun_lahir) >= '".addslashes($_POST['txt_julat_umur'])."' 
                        AND  (YEAR(NOW()) - tahun_lahir) <= '".addslashes($_POST['txt_julat_umur2'])."' ";
                }

                $operator = 'AND';

        }

            // check if job position was submitted to be search for
            if(isset($_POST['txt_jawatan']) and $_POST['txt_jawatan'] != '') {

            $jawatan = str_replace(', ', ',', $_POST['txt_jawatan']);

            $jawatan_array = explode(',', $jawatan);

            foreach($jawatan_array as $one_jawatan) {

                $qry .= "$operator jawatan LIKE '$one_jawatan' ";

                $operator = 'AND';
            }
          } 

            // check if certficate level was submitted to be search for
            // checkbox form
            if(isset($_POST['txt_taraf_pendidikan']) and $_POST['txt_taraf_pendidikan'] != '') {
            $didik_arr = explode(',', $_POST['txt_taraf_pendidikan']);
            $jum_didik = count($didik_arr) - 1;
            //echo "jum_didik = ".$jum_didik;
            if($jum_didik > 0){
            $d = 0;
                foreach ($didik_arr as $value){
                $d++;
            //echo "; value::: ".$value." :::";
                    if($d == 1){
                        if($str == ''){
                            $str = " WHERE ";   
                        }
                    else{
                        $str .= " AND ";    
                    }
                    $temp_didik .= $value;
                    }
                    else{
                        if($value != ''){
                            $temp_didik .= ",".$value;
                            }
                        }
                }
            }
            $qry .="$operator id_taraf_pendidikan IN '(".$temp_didik.")'";
            }

            // check if course was submitted to be search for
            if(isset($_POST['txt_kursus']) and $_POST['txt_kursus'] != '') {

            $kursus = str_replace(', ', ',', $_POST['txt_kursus']);

            $kursus_array = explode(',', $kursus);

            foreach($kursus_array as $one_kursus) {

                $qry .= "$operator kursus LIKE '$one_kursus' ";

                // change the operator from WHERE to AND
                $operator = 'AND';
            }
          }


        $res = mysql_query($qry);
        while($row = mysql_fetch_assoc($res)) {
            if($row['no_kp'] != ''){
                    if(!in_array($row['no_kp'], $senarai_kp)){
                        array_push($senarai_kp, $row['no_kp']); 
                    }
                }
            }
    } 

    $_SESSION['sqls'] = $sql;
    ?>

    <strong>Keputusan Carian</strong><br /><br />
    <table border="1" style="min-width:800">
      <tr>
        <th width="50" scope="col">Bil</th>
        <th width="200" scope="col">Nama</th>
        <th width="100" scope="col">No IC</th>
        <th width="200" scope="col">Alamat</th>
        <th width="100" scope="col">Jantina</th>
        <th width="80" scope="col">Umur</th>
        <th width="120" scope="col">Kelulusan</th>
        <th width="120" scope="col">Status Calon</th>
        <th width="70" scope="col"></th>
      </tr>

     <?php
    for($i = 0; $i < count($senarai_kp); $i++){
    //$i = 0;

        $sql = "SELECT *, (YEAR(NOW()) - tahun_lahir) AS umur FROM jobseeker WHERE no_kp = '".$senarai_kp[$i]."'";
        //echo "<br><br>".$sql;
        $res = mysql_query($sql." limit ".$start.",".$limit) or die(mysql_error().$sql);
        $row = mysql_fetch_array($res);
        //$i++;

        $str_didik = '<table border="0">';

        $sql = "SELECT a.*, b.nama as jenis_didik FROM jobseeker_pendidikan a 
        INNER JOIN lsttaraf_pendidikan b ON a.id_taraf_pendidikan = b.id 
        WHERE no_kp = '".$row['no_kp']."' ORDER BY taraf ASC";
        $res_taraf = mysql_query($sql);
        while($row_taraf = mysql_fetch_array($res_taraf)){
            $str_didik .= "<tr valign=\"top\"><td>- </td><td>".ucwords(stripslashes($row_taraf['jenis_didik'])).' '.ucwords(stripslashes($row_taraf['kursus']))."</td></tr>";
        }

        $str_didik .= '</table>';
    ?>  

    <tr valign="top">
        <td><?php echo ($i+1); ?></td>
        <td><?php echo displayNama(ucwords(stripslashes($row['nama'])), $row['no_kp']); ?></td>
        <td><?php echo ucwords(stripslashes($row['no_kp'])); ?></td>
        <td><?php echo stripslashes($row['alamat']); ?></td>
        <td><?php echo ucwords(stripslashes($row['jantina'])); ?></td>
        <td><?php echo ucwords(stripslashes($row['umur'])); ?></td>
        <td><?php echo $str_didik; ?></td>
        <td><?php echo ucwords(stripslashes($row['status_kerja'])); ?></td>
        <td align="center"><img src="images/down_16.png" width="16" height="16" border="0" onclick="javascript:insSenaraiPendek('<?php echo stripslashes($row['no_kp']); ?>')" style="cursor:pointer" align="absbottom"></td>
    </tr>
    <?php
    }
    if($i == 0){
    ?>
        <tr><td colspan="8">Tiada rekod dijumpai.</td></tr>
    <?php
    }
    ?>  
    </table>
    <br />
    <a href="carian_emel.php">Excel</a>

I know im using mysql_* , but this is just a test .. Still learning bout mysqli and PDO . Please help me, thanks

Edited by nazree.zeko

2
Contributors
1
Reply
18
Views
3 Years
Discussion Span
Last Post by cereal
0

Hi, show the query generated by your script, i.e.:

print_r($qry);

Then try to run the same query through a mysql client, from shell or by PHPMyAdmin. And add:

$res = mysql_query($qry) or die(mysql_error());

To be sure it runs fine.

This question has already been answered. 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.