PHP- Auto fill the data when ID is provided
I have two forms here. Registration and Payment. In the registration form i have fields hosteladmissionnumber,student name,sex,semester,branch.etc.. and in the Payment form,I have hosteladmissionnumber,Demand Draft number,DD date,Bank Name etc...
The question here is: When i enter the hosteladmissionnumber in payment form, it must display the Text boxes of studentname,semester,Branch(only 3 fields) from the registration table in my database.How can i do this? Any suggestions? Do i really need to do this with three text boxes or is there any alternate way? Im using PHP as frontend and Mysql as Backend.
For payment part, the code is:(PHP)
<?php
session_start();
$hostad=$_POST['hosteladmissionno'];
//$sem=$_POST['student_name'];
//$sem=$_POST['semester'];
$ddno=$_POST['ddno'];
$dd=$_POST['ddamount'];
$bname=$_POST['bankname'];
$dddate=$_POST['dddate'];
$mess=$_POST['messamount'];
开发者_开发技巧 $room=$_POST['roomamount'];
$receipt=$_POST['receiptnumber'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
die('Unable to connect'.mysql_error());
}
mysql_select_db('hostel',$con);
if(isset($sem)&&isset($dd)&&isset($bname)&&isset($dddate)&&isset($mess)&& isset($room)&&isset($receipt))
{
$r1="INSERT INTO payment(hosteladmissionno,semester,ddno,ddamount,bankname,dddate,messamount,roomamount,receiptnumber)
VALUES ($hostad','$sem','$ddno','$dd','$bname','$dddate','$mess','$room','$receipt')";
mysql_query($r1);
$r2="UPDATE registration SET status_flag=1 WHERE hosteladmissionno='$hostad'";
mysql_query($r2);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
// echo 'hello("',$rollnumber,'");', "\n";
echo "<script language='javascript'>alert('Successfuly Paid');</script>"; }
mysql_close($con);
?>
You need AJAX for this. You can dynamicaly.
See this example or this.
AJAX tutorial -> http://www.w3schools.com/ajax/default.asp
I guess, it more logical problem than technical.
Find the student by student by
hosteladmissionnumber
, I guess that is going to be primary key.Show the student information on Payment Form.
use jquery ajax.
<script>
function getstudent(element)
{
var id = $(this).val();
$.ajax({
url: 'yoururl.php',
data: { 'id' : id}, //send id
success: function(data) {
//parse the result
//and display success function
//also get the student info and display
//it on other text value
$('#stu_name').val(data.name);
},
dataType: 'json' //also can be xml
});
}
</script>
<input name="hosteladmissionno" id="admissionno" onblur="getstudent(this);"/>
<input name="stu_name" id="stu_name" type="text"/>
you can use AJAX. you can download jquery from this link http://jquery.com/
you can use jquery and java script code simultaneously without any problem.
Include downloaded jquery file same as java script file
精彩评论