时间:2021-07-01 10:21:17 帮助过:11人阅读
期待有人回答中。。。
  把sql,输出,看看是什么  
也没有转义,是不是输入了单引号? 
  if(isset($_POST["submit"])){  
  $sql = "insert into users(username, email) values('$_POST[username]', '$_POST[email]')";  
  mysqli_query($conn, $sql);  
  echo "添加成功";  
  }  
  
把这几行前面的全角空格换成英文空格 
  $sql = "insert into users(username, email) values('$_POST[username]', '$_POST[email]')";  
  mysqli_query($conn, $  
  
第二行mysql 多了个 i  啊 
$_POST[username]应该加引号 ====》$_POST[‘username’] 同理email也是
打印$sql就知道sql语句有没有问题了
   if(isset($_POST["submit"])){   
  $sql = "insert into users(username, email) values('$_POST[username]', '$_POST[email]')";   
  mysqli_query($conn, $sql);   
  echo "添加成功";   
  }   
   
把这几行前面的全角空格换成英文空格  
    $conn = new mysqli("localhost", "root", "123123");   $conn->select_db("company");   //mysql_query("set name 'gb2312'");   $conn->set_charset("utf8");   
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\AppServ\www\form_write_mysql\add.php on line 8  
添加成功  
  
  
实际上这个 $conn , 已经正确使用了,但是 我在 add。php 中   
echo $conn.'
';  
却没有输出结果 ,这是为什么呢?   
@jordan102  
 
    include("conn.php");  
?>  
  
include 前面同样有全角空格。  
既然用面向对象方式连接数据库了,为什么不用面向对象方式执行sql呢。  
$conn->query($sql); 
add.php 里面MySQL语句错了,原句mysqli_query($con你, 改成mysql_query($con你,
还不结贴啊 。