PHP连接数据库问题
帮我看下,数据库没内容呐,但是我看着感觉没错呀
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<style type=”text/css”>
body{background-color:#CCCCCC;本文来源gaodai#ma#com搞*!代#%^码$网!搞代gaodaima码
margin:0px;}
.head{height:300px;
text-align:center;}
.gong{height:20px;
background-color:#33CCFF;}
</style>
<body>
用户
密码
用户注册
<?php
include “comm.php”;
?>
<meta http-equiv=Content-Type content=”text/html; charset=gb2312″>
<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”,”注册成功”);
}
?>
第一次密码:
第二次密码
——解决方案——————–
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;}#改为
#后面添加
#导致php页面$pw = md5($_POST['pw1']); #没有值,不信你echo出来试试需改为:$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'"); $res = mysql_query($sql,$conn); #如果sql未执行成功,将错误打印出来 if(!$res) die("SQL:{$sql}
Error:".mysql_error()); if(mysql_affected_rows() > 0) get_show_msg("left.html","注册成功"); else echo "注册失败".mysql_error(); mysql_close($conn);