dimanche 15 février 2015

problems with mysql and XMLHttpRequest + php


I would like to add a search function for my mysql database. So if I type 'Test' it shows all users with the word Test in it. But the communication from my php document to the mysql SELECT .... doc doest't work for me. I would like that after clicking 'search' the results are shown below the search input part (in the #search_name_logs div).


Well ... I hope you understand my question, I know my English could be much better. Sorry for my bad English ..


Here is the main php script:



<script>

function submitSearch(){
var search = searchtermname.value;
var xmlhttp = new XMLHttpRequest();

xmlhttp.open('GET','findusername.php?search='+search);
xmlhttp.send();

var searchname_result = xmlhttp.load('GET','findusername.php?search='+search);

$('#search_name_logs').load(searchname_result);
}

</script>

(...)
<script type="text/javascript" src="http://ift.tt/19cXiAj"></script>
<div class="pmaddtalk_box_name"><span id="open_add_name" style="cursor:pointer;"><div>
<img src="png/find_user-50.png" class="pmaddtalk_icon">
<p class="pmaddtalk_find_text">Search by Name</p>
</div></span>
<article id="open_now_add_name">
<input name="searchtermname" class="boxformal boxformal-search" placeholder="Search by Name"></input>
<a href="#" onClick="submitSearch()" class="search_btn">Search</a><br>
<div id="search_name_logs"></div>
<br><br>
</article>
<script>
$("#open_add_name").click(function() {
$( "#open_now_add_name" ).toggle( "blind" );
});
</script>
</div>


Of course it is not the whole script :) So here is the php mysql connection script:



<?php
session_start();

$search = $_REQUEST['search'];

$con = mysql_connect("localhost", "...", "...");
mysql_select_db('ibm',$con);
$result1 = mysql_query("SELECT * FROM users WHERE username = '$search'");

while($extract = mysql_fetch_array($result1)){
echo "<p>" . $extract['username'] . "</p>";
}


?>




Aucun commentaire:

Enregistrer un commentaire