我写了这段代码

<?php
  mysql_connect ("localhost","root","root");
  mysql_select_db ("new");
  $newusername=$_POST ['newusername'];
  $newpassword=$_POST ['newpassword'];
  $submit=$_POST ['submit'];
  if($submit) {
    $newaccount= "INSERT INTO users (name,password) VALUES ("$newusername","$newpassword")";
    $result=mysql_query($newaccount);
    if ($result) {
      print "account has been created"."<meta http-equiv="refresh" content="5;login.php">";
    }
    else {
      echo " The account is already exist";
    }
  }
?>


但它在“插入到”行的第8行显示错误

最佳答案

双引号有问题。您可以添加串联:

$newaccount = "INSERT INTO users (name,password) VALUES ('" . $newusername . "','" . $newpassword . "')";


附言不要使用mysql_ *函数(不建议使用mysql扩展名),而应使用mysqli_ *。

关于php - 为什么插入不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24881469/

10-10 06:37