日期:2014-05-17 浏览次数:20447 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <form action="" method="post" name="myform"> <table> <tr><td>用户名:</td><td><input type="text" name="name"/></td></tr> </table> <input type="submit" name="submit" value="搜索" /> </form> <?php if(isset($_POST['name'])&&(!empty($_POST['name']))){ $name = $_POST['name']; $name = mysql_escape_string($name); mysql_connect("数据库地址", "用户名", "密码") or die("Could not connect: " . mysql_error()); mysql_select_db("数据库名"); $result = mysql_query(" SELECT * FROM 数据表名 WHERE 姓名对应的数据字段名='".$name."' "); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { var_dump($row); //根据需要取出相应的数据,你要显示的数据字段名 echo "姓名:".$row['name']; } mysql_free_result($result); }else { echo '用户名不能为空!'; } ?> </body> </html>