<?php /******************************** *** 功能:选择指定的MySQL数据库 *********************************/ ?> <!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" /> <title>选择数据库</title> </head> <body background="image/bg.JPG"> <table align="center"><tr><td> <img src="image/banner.jpg"> </td></tr><tr><td background="image/head.JPG" align="center"> <form action="" method="post"> <select name="select"> <option value="1" selected="selected">请选择数据库</option> <!--连接数据库--> <?php $conn = mysql_connect("localhost","root",""); $rs = mysql_query("show databases");//查询操作 //将数据库名称以下拉列表的方式显示 while($rst = mysql_fetch_array($rs)){ $i = 0; echo "<option value = ".$rst[$i].">".$rst[$i]."</option>"; $i ++; } ?> </select> <input type="submit" name="sub" value="确定" /> </form> </td></tr><tr><td background="image/head.JPG"> <?php if(!empty($_POST["sub"])){ if($_POST["select"] == "1"){ echo "<script>alert(‘请选择数据库‘);</script>"; }else{ if(mysql_select_db($_POST["select"],$conn)){ echo "<script>alert(‘已经连接到指定的数据库‘);</script>"; mysql_close(); }else{ echo "<script>alert(‘出错了‘);</script>"; } } } ?> </td></tr></table> </body> </html>
时间: 2024-10-03 02:24:46