Home >Backend Development >PHP Tutorial >数据无法写入数据库解决思路

数据无法写入数据库解决思路

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 10:11:451178browse

数据无法写入数据库
session_start();
[email protected]_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();}
}
?>

------解决方案--------------------

探讨
$result1=$coon->query($str); //这行有错误,应该怎么改?
$row=$result1->fetch_row();

------解决方案--------------------
[email protected]_connect("localhost", "root", "ch12345") or die("数据库链接错误");
$coon->query($str);
还没见过这样写的!仔细看看手册先http://www.php.net/manual/zh/book.mysql.php
------解决方案--------------------
探讨

[email protected]_connect("localhost", "root", "ch12345") or die("数据库链接错误");
$coon->query($str);
还没见过这样写的!仔细看看手册先http://www.php.net/manual/zh/book.mysql.php
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn