Submit form variable to lightbox

Discussion in 'PHP' started by sg552, Aug 13, 2010.

  1. #1
    Hello everyone,

    I need help with sending form variable to a lightbox.

    OK, what this page suppose to do is user will insert his ID, click Papar ~Display in English, the page will refresh and his examination result will be output in the lightbox. More information on my test page here:

    http://www.smkhutankampong.co.cc/infopendidikan.php
    paste 158756873427 into the form and click Papar.

    that lightbox popup is a remote file so I can paste mysql query in it. Also its not working actually. I already set the query manually like this:
    $result = mysql_query("SELECT * FROM exam_data WHERE no_KP='158756873427'");  
    PHP:
    what I need is the form from infopendidikan.php to send its variable to the lightbox remote page resultpopup.php. Also you can click on the query popup on the left menu to see the fixed query. resultpopup.php need to retrieve variable from infopendidikan.php.

    Anyway this is infopendidikan.php code:

    <?php
    
    //if the "submit"variable does not exist
    //form has not been submitted
    //display initial page
    if (!$_POST['submit'])
    {
    ?>
     <p>Sila masukkan No. Kad Pengenalan anda diruangan yang disediakan dan klik butang <i>Papar</i> keputusan.</p>
     
      <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" name="form1" id="form1" >
    <p>
    <label><strong>No. Kad Pengenalan:</strong></label> 
    <input name="no_KP" type="text" size="20" maxlength="20" id="FirstName" value="Contoh: 896537841253"/> 
    <label><strong>Jenis Peperiksaan:</strong></label> 
    <label for="select"></label>
    <select name="select" id="select">
      <option value="PMR">PMR</option>
      <option value="SPM">SPM</option>
    </select>
    <br /><br />
    
    <input class="button" type="submit" name="submit" id="button" value="Papar" />
    </p>
    </form>
    
    <?php
    
    }
    
    
    else
    {
    //if the "submit" variable exists
    //the form has been submitted
    //look for and process form data
    //display result
    
    // Make a MySQL Connection
    
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("exam") or die(mysql_error());
    
    // tapis input pengguna
    $no_KP = mysql_real_escape_string($_POST['no_KP']);
    $select = mysql_real_escape_string($_POST['select']);
    
    // Get a specific result from the "example" table
    $result = mysql_query("SELECT * FROM exam_data WHERE no_KP='$no_KP' AND jenis_exam='$select'");  
    
    // get the first (and hopefully only) entry from the result
    $row = mysql_fetch_array( $result );
    // Print out the contents of each row into a table 
    
    if ($row['no_KP'] == "")
    {
    	echo "<p>Tiada maklumat dijumpai :(";
    
    }
    else
    {
    echo "<p><div align=\"center\"><h3>Penilaian Menengah Rendah<br>SMK Hutan Kampong</h3> </div>";
    
    
    	echo "<script type='text/javascript'>
    $(document).ready(function(){ 
                    jQuery.facebox({ ajax: 'resultpopup.php' })
    })
    </script>";
    
    echo "&nbsp;&nbsp;&nbsp;<b>Nama :</b> " .$row['nama']. "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>No. K/P :</b> " .$row['no_KP'];
    // Get a specific result from the "example" table
    $result = mysql_query("SELECT * FROM exam_data WHERE no_KP='$no_KP' AND jenis_exam='$select' ORDER BY kod_subjek ");  
    
    echo "<form><p><table border='0'>";
    echo "<tr> <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kod M/P&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th> <th><div align=\"left\">Nama Mata Pelajaran&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th> <th>Gred</th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    	// Print out the contents of each row into a table
    	echo "<tr><td>"; 
    	echo "<div align=\"center\">" .$row['kod_subjek']. "";
    	echo "</td><td>"; 
    	echo $row['subjek'];
    	echo "</td><td>"; 
    	echo "<div align=\"center\">" .$row['gred'];
    	echo "</td></tr>"; 
    } 
    
    echo "</table></p></form>";
    echo "&nbsp;&nbsp;&nbsp;<A HREF=\"javascript:window.print()\">Cetak</A></p>";
    
    }
    }
    ?>
    PHP:
    If I can get the result in the lightbox without page refresh that will be more cool. :) oh yes the lightbox I'm using is facebox from http://famspam.com/facebox/

    Any help is appreciated. Thanks in advance :)
     
    sg552, Aug 13, 2010 IP