简体   繁体   English

我无法从php页面将用户添加到mysql数据库

[英]I can't add users to mysql database from php page

I have done a research before posting this question here i know it has been asked for few times but non of the answers solved my issue i am following a tutorial and i had to create 2 php pages ,first one to connect with the sql database 我已经进行了研究,然后再在此处发布此问题,我知道已经被问过几次了,但是没有答案解决了我的问题。我正在学习一个教程,我必须创建2个php页面,第一个连接sql数据库
Page name myfirstphpweb.php Code: 页面名称myfirstphpweb.php代码:

$DBName ='id6_myfirstdb ';
$DBServer='localhost';
$DBUsername='id6_b';
$DBPassword='123456';
$DBConnect= new mysqli($DBServer,$DBUsername,$DBPassword,$DBName);
if($DBConnect->connect_error){
die ("connection failed:". $DBConnect->connect_error);
}
else{ echo "connection Successful! " ; 
}

second page to insert a user into the database page name: insertusersql.php Code: 将用户插入数据库的第二页页面名称:insertusersql.php代码:

include 'myfirstphpweb.php';
$insertusersql="INSERT INTO users (name,password,email,address) 
          VALUES ('AVALUE','123456','AVALUE@M.com','ALOCATION');";



    if($DBConnect ->query($insertusersql)===TRUE){
             echo "User added Successfully";
             }else{
             echo "Some thing is wrong";
             }

I used this as well if( mysqli_query($DBConnect,$insertusersql)){ 如果((mysqli_query($ DBConnect,$ insertusersql)){

but i get the error message i put "some thing is wrong" 但是我收到错误信息,我说“某事是错误的”

on mysql phpmyAdmin i get this msg "Showing rows 0 - 0 (1 total, Query took 0.0066 seconds.)" 在mysql phpmyAdmin上,我得到此消息“显示行0-0(共1行,查询花费0.0066秒。)”

I can add users manually on phpmyAdmin 我可以在phpmyAdmin上手动添加用户

my table has id (int) auto increment primary key, name (varchar(70)), password(varchar(70)),email(varchar(70)),address(varchar(200)),registertime(varchar(100)) utf8_unicode_ci 我的表具有id(int)自动递增主键,名称(varchar(70)),密码(varchar(70)),电子邮件(varchar(70)),地址(varchar(200)),registertime(varchar(100) )utf8_unicode_ci

$DBName ='id6_myfirstdb '; $ DBName ='id6_myfirstdb';

your code is fine, but you have white space in database name. 您的代码很好,但是数据库名称中有空白。 if it's not mistyping here, could be the problem. 如果不是这里有问题,可能是问题所在。

include 'myfirstphpweb.php';
$insertusersql="INSERT INTO users (name,password,email,address) 
      VALUES ('AVALUE','123456','AVALUE@M.com','ALOCATION')";

if($DBConnect->query($insertusersql)===TRUE){
         echo "User added Successfully";
         }else{
         echo "Some thing is wrong";
         }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM