数据无法写入数据库解决思路
程序员文章站
2022-06-05 23:02:07
...
数据无法写入数据库
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 "";
}
else {echo "注册失败".mysql_error();}
}
?>
------解决方案--------------------
------解决方案--------------------
$coon=@mysql_connect("localhost", "root", "ch12345") or die("数据库链接错误");
$coon->query($str);
还没见过这样写的!仔细看看手册先http://www.php.net/manual/zh/book.mysql.php
------解决方案--------------------
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 "";
}
else {echo "注册失败".mysql_error();}
}
?>
------解决方案--------------------
------解决方案--------------------
$coon=@mysql_connect("localhost", "root", "ch12345") or die("数据库链接错误");
$coon->query($str);
还没见过这样写的!仔细看看手册先http://www.php.net/manual/zh/book.mysql.php
------解决方案--------------------
相关文章
相关视频