日期:2014-05-16  浏览次数:20333 次

php基础教程--数据库连接及登录注册
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Login Page</title>
	<link rel="shortcut icon" href="/favicon.ico">
	<link rel="stylesheet" type="text/css" href="js/style.css" />
</head>

<body>
	<form id="login-form" action="b.php" method="post">
		<fieldset>		
			<legend>Log in</legend>			
			<label for="login">username</label>
			<input type="text" id="login" name="username"/>
			<div class="clear"></div>		
			<label for="password">passwords</label>
			<input type="password" id="password" name="password"/>
			<div class="clear"></div>
			<br />
			<br><br>
			<input type="submit" style="margin: -20px 0 0 287px;" class="button" name="commit" value="submit"/>	
		</fieldset>
	</form>	
<br /><br />
<br />
<br />
<br />
<br />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Login Page</title>
	<link rel="shortcut icon" href="/favicon.ico">
	<link rel="stylesheet" type="text/css" href="js/style.css" />
</head>

<body>
	<?php 
	$username = $_POST['username'];
	$passwords = $_POST['password'];
	if(is_null($username)||is_null($passwords)){
		echo "请确定用户名和密码都已填写";
	}else {
		$sql="select 'name','password' from userlist where name='".$username."'and password = '".$passwords."'";
	}
	class DataBase{
		public $dbhost = "localhost";
		public $dbuser = "root";
		public $dbpass = "123456";
		public $dbname = "test";
		function conn(){
			$dbconn = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass) or die("database error!".mysql_error());
			mysql_select_db($this->dbname) or die("can not connect database:".mysql_error());
			return $dbconn;
		}
		function indb($in_sql){
			$result_indb = mysql_query($insql) or die("can not run the sql language$insql:".mysql_error());
			return $result_indb;
		}
	}
	$db = new DataBase();
	$db->conn();
	echo $db->indb($sql);
	?>
<br /><br />
<br />
<br />
<br />
<br />
</body>
</html>

好了,同学们,这个可以作为一个模板,好好学习,程序员最重要的是要独立自主,自学能力一定要强。