日期:2014-05-17  浏览次数:20606 次

PHP连接数据库问题
帮我看下,数据库没内容呐,但是我看着感觉没错呀
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<style type="text/css">
body{background-color:#CCCCCC;
margin:0px;}
.head{height:300px;
text-align:center;}
.gong{height:20px;
background-color:#33CCFF;}
</style>
<body>
<div class="head">
<div class="gong">用户登录</div>
<form method="post" action="" name="myform">
用户<input type="text" name="username"><br>密码<input type="password" name="pw"><br><input type="submit" name="submit" value="提交"><input type="reset" name="reset" value="重置">
<A href="register.php">用户注册</A>
</form>
</div>
</body>
</html>



<?php
include "comm.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD><TITLE>在线留言-留言板</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
</HEAD>
<BODY>
<script type="text/javascript">
function check(){
if(myform.name.value==""){
alert("用户名不能为空!");
return false;
}
if(myform.pw1.value=="" | myform.pw2.value==""){
alert("密码不能为空!");
return false;
}
if(myform.pw1.value!=myform.pw2.value){
alert("两次输入的密码不一致!")
return false;
}
return true;
}
</script>
<?php
 if(isset($_POST['username'])){
  $user = $_POST['username'];
  $pw = md5($_POST['pw1']);

  $conn = mysql_connect("localhost","root","123456");
  mysql_select_db("car");
  $sql = "insert into car_user (user_name,pw) values('$user','$pw')";
  mysql_query("set names 'gb2312'");
  mysql_query($sql,$conn);
  mysql_close($conn);
  get_show_msg("left.html","注册成功");
 }
?>

  <FORM id=myform name=myform action="" method=post onsubmit="return check();">
  <INPUT id=name size=10 name=username><br>第一次密码:<INPUT id=pw1 size=30 type=password name=pw1><br>第二次密码<INPUT id=pw2 size=30 type=password name=pw2><br>
<input type="submit" name="submit" value="提交"><input type="reset" name="reset" value="重置">
</FORM>
</BODY>
  </HTML>


------解决方案--------------------
mysql_query($sql,$conn) or die(mysql_error()); //这样有错误提示么
------解决方案--------------------
mysql_query($sql,$conn) or die(mysql_error());
------解决方案--------------------
HTML code

#js中pw1、pw2未定义,return停掉了,下面的代码就未执行
if(myform.pw1.value=="" | myform.pw2.value==""){
alert("密码不能为空!");
return false;
}
#改为
<input type="password" name="pw1"><br>
#后面添加
<input type="password" name="pw2"><br>

#导致php页面
$pw = md5($_POST['pw1']); #没有值,不信你echo出来试试
需改为:
$conn = mysql_