hello, I have some problem with this code.
Jacasript used in AJAX:
var xmlHttp;
function showUser(str) {
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request"); return;
}
var url="getuser.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true); xmlHttp.send(null); }
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("txtHint").innerHTML=xmlHttp.responseText; } }
function GetXmlHttpObject() {
var xmlHttp=null;
try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }
catch (e) { //Internet Explorer
try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }
return xmlHttp; }
The PHP page:
<?php $q=$_GET["q"];
$con = mysql_connect('localhost', 'peter', 'abc123');
if (!$con) { die('Could not connect: ' . mysql_error());
}
mysql_select_db("ajax_demo", $con);
$sql="SELECT * FROM user WHERE id = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td><input type = 'text' name='username' id='username' size ='35' value=". $row['username'] ." ></td>";
echo "</tr>"; } echo "</table>";
mysql_close($con); ?>
I had tried this code but I want to display the result in a text box. The user was found and it displayed in the text box. But only one word appeared in the text box. I don't want to separate the user name to first name and last name. So, the user name is in one field only.
So, for example the user name is 'hulk hogan'. Only hulk displayed in the text box. When I just displayed it without the text box, the name displayed all word, 'hulk hogan'. So, what should I do so the name in text box will display all word. Please help me.