This question is an exact duplicate of:
i want to write a code so when the i insert a character inside my form, then users(in my database) who their names start with the character i inserted show up(like if facebook) but my problem is when i insert a character, instead of just printing the users names, my page xeroxes in that section like this: (i know that i have asked this question once but i didn't get any answer and i really have to solve this problem)
here goes my code:
<div id="mymessages">
<div>
<br><br>
<div style="display:inline; border:1px solid gray; margin-left:8px;" onClick="myinbox()"><b>پیام های من</b></div>
<div style="display:inline; border:1px solid gray; margin-left:8px;"><b onClick="sendnewmsg()">ارسال پیام جدید</b></div>
</div>
<script>
function myinbox(){
document.getElementById("myinbox").style.display="block";
document.getElementById("sendnewmsg").style.display="none";
}
function sendnewmsg(){
document.getElementById("sendnewmsg").style.display="block";
document.getElementById("myinbox").style.display="none";
}
</script>
<div id="sendnewmsg">
<form enctype="multipart/form-data" id="sendmessage" style="text-align:center;" name="sendmessage" method="post" action="userpanel.php">
TO: <input onKeyUp="selrec(this.value)" type="text" id="receiver" name="to"><br><br>
<script>
function selrec(name)
{
if(name.length==0)
{
document.getElementById('selectrec').innerHTML="no suggestion";
return;
}
if(window.XMLHttpRequest)
myrequest=new XMLHttpRequest();
else
myrequest=new ActiveXObject("Microsoft.XMLHTTP");
myrequest.onreadystatechange=function()
{
if (myrequest.readyState==4 && myrequest.status==200)
{
document.getElementById('selectrec').innerHTML=myrequest.responseText;
}
}
myrequest.open("GET","userpanel.php",true);
myrequest.send("typedname="+name);
}
</script>
<div id="selectrec">
<?php
if(isset($_POST['typedname'])){
$conn=mysqli_connect('localhost','root');
if (!$conn)
die("couldn't connect" . mysql.error());
$typedname=$_REQUEST['typedname'];
mysqli_select_db($conn,'swimsafe');
$bringusers='SELECT * FROM users WHERE firstname LIKE"'.$typedname.'%" OR lastname LIKE"'.$typedname.'%" LIMIT 3';
$getuserstyped=mysqli_query($conn,$bringusers);
if(!$getuserstyped)
die("couldn't choose the users" .mysql_error());
while($rows=mysqli_fetch_array($getuserstyped))
{
echo $rows['firstname'] . " " . $rows['lastname'];
}
mysqli_close($conn);
}
?>
</div>
SUBJECT: <input type="text" name="subject" ><br><br>
CONTENT:<br> <textarea form="sendmessage" style="height:150px; width:300px;" name="content">
</textarea>
<br><br>
<input type="submit" onClick="return checkreciever()" id="submitmsg" name="submit" value="send">
</form>
</div>
</div>