Click here to Skip to main content
15,742,357 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
// First of all, don't make use of mysql_* functions, those are old
$pdo = new PDO("mysql:host=localhost;dbname=erp1314;charset=utf8", "root", "");
<link type="text/css" rel="stylesheet" href="style.css"/>
<script type="text/javascript" src=""></script> <!-- You will need jQuery (or anyother javascript framework) to accomplish your goal cause you need ajax -->
        <div id="content">
           <h1 align="center">Add Training</h1>
<form action="employess.php" method="post">
                        Training ID:
                        <input type="text" name="Training_ID">
                        Employee ID:
                        <select id="JOB_NO" >
                            <option value="">Select one</option>
                            $st = $pdo->prepare("SELECT JOB_NO FROM mm_client_loc_job");
                            $rows = $st->fetchAll(PDO::FETCH_ASSOC);
                            foreach ($rows as $row) {
                                ?><option value="<?php echo $row ['JOB_NO']; ?>"><?php echo $row ['JOB_NO']; ?></option><?php
                        First name:
                        <input type="text" name="CLIENT_NAME" id="CLIENT_NAME">
                        Last name:
                        <input type="text" name="LOC_NAME" id="LOC_NAME">
                        Training required?
                        <select name="Training">
                            <option value="">Select...</option>
                            <option value="Customer Service">Customer Service</option>
                            <option value="Bailer">Bailer</option>
                            <option value="Reception">Reception</option>
                            <option value="Fish & meat counters">Fish & meat counters</option>
                            <option value="Cheese counters">Cheese counters</option>
                    <input type="submit">
    <script type="text/javascript">
        $(function() { // This code will be executed when DOM is ready
            $('#JOB_NO').change(function() { // When the value for the Employee_ID element change, this will be triggered
                var $self = $(this);
             // We create an jQuery object with the select inside

                $.post("getEmployeeData.php", { JOB_NO : $self.val()}, function(json)
                    if (json && json.status) {



$pdo = new PDO("mysql:host=localhost;dbname=erp1314;charset=utf8", "root", "");

header("Content-Type:application/json; Charset=utf-8");

// As you can see, here you will have where Employee_ID = :employee_id, this will be
// automatically replaced by the PDO object with the data sent in execute(array('employee_id' => 
// This is a good practice to avoid Sql Injection attacks

$st = $pdo->prepare("SELECT CLIENT_NAME, LOC_NAME FROM mm_client_loc_job WHERE JOB_NO = :job_No LIMIT 1");
$st->execute(array (':job_No' => $_POST['Job_No']));
echo (job_no);
$data = $st->fetch(PDO::FETCH_ASSOC);
echo json_encode(array ('status' => true, 'name' => $data ['CLIENT_NAME'], 'lastname' => $data ['LOC_NAME']));
Updated 27-Dec-13 10:11am
Er. Tushar Srivastava 27-Dec-13 16:13pm    
Have you commented out the line echo (job_no) It is an error as per I can see.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900