数据无法写入数据库
session_start();
$coon=@mysql_connect("localhost", "root", "ch12345") or die("数据库链接错误");
mysql_select_db("literature", $coon);
mysql_query("set names 'UTF-8'");
@$username=$_POST['username'];
@$password=$_POST['password'];
@$email=$_POST['email'];
@$sex=$_POST['sex'];
@$constallation=$_POST['constallation'];
$time=time();
$str="select * from user where username={$username}";
$result1=$coon->query($str); //这行有错误,应该怎么改?
$row=$result1->fetch_row();
if($row)
{
$temp="已有人注册此名,请重新选择名字!";
echo $temp;
echo"返回";
}
else {
$sql="INSERT INTO user(username,sex,time,constallation,password,email)".
" VALUES('$username','$sex',now(),'$constallation','$password','$email')";
//$sql="INSERT INTO user VALUES($username,$sex,$time,$constallation,$password,$email)";
$result=$coon->query($sql);
if($result==true)
{
$_SESSION['mail']="注册成功,请登陆";
echo "<script>window.location.href='login.php'</script>";
}
else {echo "注册失败".mysql_error();}
}
?>
------解决方案--------------------