php pdo code to search and echo from textbox
419
my form has receipt_no textbox..
I Need to search data on textbox blur event or key down event of textbox.
from this receipt_no textbox.I need to search database and echo values inside another textboxes...
please help...
<?php
function myFunction()
{
if(isset($_POST['receipt_no']))
{
$receipt_no = $_POST['receipt_no'];
$result = $database->getRow("SELECT receipt_no,scheme_name FROM scheme_master where receipt_no = :receipt_no",array(':receipt_no'=>$receipt_no));
if($result!=0)
{
while ($row = $result->fetchObject())
{
echo $row->scheme_name;
}
}
}
}
?>
<form action="" method="post">
<input type="text" name="receipt_no" onblur="myFunction()" />
</form>
echo value inside this textbox---
<input type="text" value="<?=$scheme_name;?>" name="scheme" class="field size2" />
Answer
Solution:
Right two methods, PHP only and AJAX javascript as some have mentioned.
First PHP only:
You don't need the attribute
onblur
attribute for this method. This is a 'self' operating page method.The next method is javascript method where the
onblur
attribute can be used:The above is a VERY basic function, it will not work in IE5-6 and may require some header data etc. And! For those that love the silly library jQuery
Some may argue to use a
GET
method for this opposed toPOST
but I prefer POST overall.