Phpajax request MySQL Database

Source: Internet
Author: User

Database: 650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7F/ED/wKiom1cxmqaTUhj0AAA33CaMLRs331.png "title=" Database Picture "alt=" Wkiom1cxmqatuhj0aaa33camlrs331.png "/>

Front Page: choseform.php

<script type= "Text/javascript" >

function Showuser (str) {

var xmlhttp;

if (str== "")

{

document.getElementById ("Txthint"). innerhtml= "";

Return

}

if (window. XMLHttpRequest)

{//code for ie7+, Firefox, Chrome, Opera, Safari

Xmlhttp=new XMLHttpRequest ();

}

Else

{//code for IE6, IE5

Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");

}

Xmlhttp.onreadystatechange=function ()

{

if (xmlhttp.readystate==4 && xmlhttp.status==200)

{

document.getElementById ("Txthint"). Innerhtml=xmlhttp.responsetext;

}

}

Xmlhttp.open ("GET", "getuser.php?q=" +str,true);

Xmlhttp.send ();


}

</script>

<body>


<form>

Select a User:

<select name= "Users" onchange= "Showuser (this.value)" >

<option value= "0" >please choose</option>

<option value= "1" >peter griffin</option>

<option value= "2" >lois griffin</option>

<option value= "3" >glenn quagmire</option>

<option value= "4" >joseph swanson</option>

</select>

</form>

<div id= "Txthint" > Customer information will be listed here ...</div>


</body>


Background files: getuser.php

<?php

$q =$_get["Q"];


$mysql _server_name= "localhost"; Database server name

$mysql _username= "root"; Connect to database user name

$mysql _password= "cxst789"; Connect Database Password

$mysql _database= "User"; The name of the database

Connecting to a database

$con =mysql_connect ($mysql _server_name, $mysql _username,

$mysql _password);

if (! $con)

{

Die (' Could not connect: '. Mysql_error ());

}


mysql_select_db ("User", $con);


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


$result = mysql_query ($sql);


echo "<table border= ' 1 ' >

<tr>

<th>Firstname</th>

<th>Lastname</th>

<th>Age</th>

<th>Hometown</th>

<th>Job</th>

</tr> ";


while ($row = Mysql_fetch_array ($result))

{

echo "<tr>";

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

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

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

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

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

echo "</tr>";

}

echo "</table>";


Mysql_close ($con);

?>


This article is from the "Phpajax request" blog, so be sure to keep this source http://15129824665.blog.51cto.com/10510385/1771839

Phpajax request MySQL Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.