0

In my project it has an interface(designation.php) which has a form. When a user enters a 'designation code'(which is a primary key) and click the 'update' button, the remaining fields should be filled accordingly. I understand that Ajax will be needed for this. but the problem is, i'm done with retrieving the result only as a single row from the database by using following query. but, this is not my objective.

while($row = mysqli_fetch_assoc($run1)) {
   echo "<tr id='tr'>";
   foreach($row AS $cell) echo "<td>$cell</td>";
   echo "</tr>\n";
}

Following is the 'designation.php'..

<form action="crud.php" method="post">
<table>
  <th >DESIGNATION</th>
  <tr>
  <td >Designation Code</td>
  <td ><input type="text" name="des_code" /></td>
</tr>
<tr>
  <td >Designation</td>
  <td><input type="text" name="desig" /></td>
</tr>
<tr>
  <td >Salary Code</td>
  <td><input type="text" name="s_code" /></td>
</tr>
<tr>
  <td >Salary Scale</td>
  <td><input type="text" name="s_scale" /></td>
</tr>
<tr>
  <td >Salary point </td>
  <td><input type="text" name="s_point" /></td>
</tr>
<tr>
  <td>Date</td>
  <td > <input type="date" name="date" /></td>
</tr>
<tr>
  <td><input type="submit" name="update" value="Update" /></td>
</tr>
</table>

I attempted many solutions but have not gotten the intended result. Any help is appreciated.

8
  • You have to set the values of your input fields... Commented Sep 13, 2013 at 4:23
  • What exactly you want dude? You want all value should be display or something else? Commented Sep 13, 2013 at 4:23
  • Thank you for the immediate response.. But, i didnt get ur reply exactly. Commented Sep 13, 2013 at 4:24
  • if the user enters designation code on designation.php and clicks update, you want to fill all form with the values from database corresponding to the designation code, right? Commented Sep 13, 2013 at 4:29
  • @Coder Thank you for reply. my need is, Fields like Designation, Salary Code, Salary Scale and etc in designation.php Should be filled automatically when the user enters the Designation Code. Commented Sep 13, 2013 at 4:29

2 Answers 2

2
  $(document).ready(function(){
       ("#form1").submit(function({
         var id=<?php echo $_POST['des_code']; ?>;

         $.ajax({
             url: 'update.php',
             type:'POST',
             data: {id:id},
             success : function (data)
             { 
                 var a=data.split('[BRK]');
                 $("#s_scale").val(a[0]);
                 // like wise store all your fields..
             }
         })
       })

upadte.php will contain

    $id=$_POST['id']; //designation id from jqyery
    $q=mysqli_query("your goes here..");
    while($row = mysqli_fetch_array($q)) 
    {
           $cell=$row[0];
           $cell.="[BRK]".$row[1];
           $cell.="[BRK]".$row[2];
     }
     echo $cell;

give id to your text field so from jquery you can add value directly.. and give form id also so you can fire onsubmit event...

i didn't try this code but hope it will work fine...

Sign up to request clarification or add additional context in comments.

Comments

1

To transfer more than one value use json!

Jquery Code::

$(function(){
  id="XXXX";
  $("form").on("submit",function(e){
     e.preventDefault();

     $.getJson("update.php",{"id":id},function(response){
        $("#value1").val(response.value1);
        $("#value2").val(response.value2);
        // like wise store all your fields..
     })
  })
})

Update.php::

$q=mysqli_query("your query");
$row = mysqli_fetch_array($q);
echo json_encode($row);  

$row will be an array containing value1, value2 and so on!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.