Live search in php -


मेरे पास यह कोड है:

  & lt; script & gt; फ़ंक्शन aa () {xmlhttp = new XMLHttpRequest (); xmlhttp.open ( "GET", "datafile.php एनएम =?" + document.form1.t1.value, झूठी); xmlhttp.send (शून्य); document.getElementById ( "d1") innerHTML = xmlhttp.responseText। } & Lt; / script & gt; & lt; form name = "form1" method = "post" & gt; & lt; input type = "text" name = "t1" ऑनक्यूप = "एए ();" वर्ग = "बॉक्स" प्लेसहोल्डर = "आप उपनाम या प्रथम नाम के माध्यम से खोज सकते हैं" & gt; & lt; div id = "d1" & gt; & lt; / div & gt;   

और डेटाफ़ाइल.php

  & lt;? php शामिल हैं "konek.php"; $ Nm1 = $ _ प्राप्त [ 'एनएम']; ? & Gt; & lt;? php $ res = mysql_query ("चुनें tblscholar से * जहां schoSurname जैसे ('$ nm1%') या schoFirstname तरह ('$ nm1%') और schoUsername! = 'व्यवस्थापक';); $ ग = 1; जबकि ($ fet = mysql_fetch_row ($ res)) {? & gt; & lt; td width = '55% '& gt; & lt; a href = "searchviewForAdmin.php? आईडी = & lt;? php echo $ fet [0]? & gt;" & gt; & lt;? php इको $ fet [1]; ? & Gt; , & Lt;? Php echo $ fet [2]; ? & Gt; & Lt;? Php echo $ fet [3]; ? & Gt; & lt; / a & gt; & lt; / टीडी & gt;   

समस्या यह है, जब मैं खोज बार में जो कुछ टाइप करता हूं तो सभी परिणाम हटाते हैं

आपको इनपुट फ़ील्ड रिक्त होने पर डेटा साफ़ करने की आवश्यकता है:

  फ़ंक्शन aa () {if (document.form1.t1.value .length == 0) {document.getElementById ("d1")। innerHTML = ""; वापसी ; } ... अपने कोड के बाकी ...}   

नोट 1: mysql_ * फ़ंक्शन वंचित, उपयोग या पीडो हैं

< मजबूत> नोट 2: आपका कोड एसक्यूएल इंजेक्शन के लिए कमजोर है।

  & lt;? Php $ nm1 = $ _ GET ['एनएम'];  

अगर (खाली ($ nm1)) {गूंजती "परिणाम नहीं"; बाहर जाएं; }

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -