Jump to content

[SOLVED] PHP and Ajax problem


june_c21

Recommended Posts

the error is when i click on any list in the pull down menu there is no data come out. what's wrong?

 

 

<td><select name="tool_list" onChange="showUser(this.value)">

        	  <?php

  $host = 'localhost';

  $user = 'root';

  $password = 'admin';

  $dbase = 'tool';



  $dblink = mysql_connect($host,$user,$password);

  mysql_select_db($dbase,$dblink);



  $query = "SELECT title,capacity from tool_list ";

      		$result = mysql_query($query);

		while($myrow = mysql_fetch_row($result))

		{

			echo "<OPTION VALUE=\"" . $myrow[0] . "\">" . $myrow[0];

		}

?>

</select></td>

 

var xmlHttp; function showUser(str)

{ 

xmlHttp = (window.ActiveXObject)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

}

var url="getuser.php"

url=url+"?id="+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;

}

 

<?php

$id=$_GET["id"];



$host = 'localhost';

$user = 'root';

$password = 'admin';

$dbase = 'tool';



$dblink = mysql_connect($host,$user,$password);

mysql_select_db($dbase,$dblink);



$sql="SELECT * FROM tool_list WHERE id = '".$id."'";



$result = mysql_query($sql);



echo "<table border='1'>

<tr>

<th>ID</th>

<th>Title</th>

<th>Model</th>

<th>Capacity</th>

<th>Quantity</th>

</tr>";



while($row = mysql_fetch_array($result))

{

echo "<tr>";

echo "<td>" . $row[0] . "</td>";

echo "<td>" . $row[1] . "</td>";

echo "<td>" . $row[2] . "</td>";

echo "<td>" . $row[3] . "</td>";

echo "<td>" . $row[4] . "</td>";

echo "</tr>";

}

echo "</table>";



?>

Link to comment
https://forums.phpfreaks.com/topic/87016-solved-php-and-ajax-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.