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

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

WBOY
Release: 2016-06-13 13:40:07
Original
1081 people have browsed it

数据无法写入数据库
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();}
}
?>

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

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

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

$coon=@mysql_connect("localhost", "root", "ch12345") or die("数据库链接错误");
$coon->query($str);
还没见过这样写的!仔细看看手册先http://www.php.net/manual/zh/book.mysql.php
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template