从php中的post方法输入表单数据

时间:2022-10-16 13:07:56

I have a database with primary key set to auto increment. I can't enter form data from a post method in php.

我有一个主键设置为自动增量的数据库。我无法从php中的post方法输入表单数据。

Here's the code. I have logins table in users database. Also a form whose action is set to below code.

这是代码。我在用户数据库中有登录表。也是一个表单,其操作设置为低于代码。

<?php 
if(isset($_POST['signup'])){
    if (isset($_POST['Full-name']) && isset($_POST['psd']) && isset($_POST['email'])) {
            $link2 = @mysqli_connect('localhost', 'root', '') or die("Oops! Can't connect");
            @mysqli_select_db($link2, 'users') or die("Can't find Database");
            $fullname = $_POST['Full-name'];
            $email2 = $_POST['email'];
            $newpassword = $_POST['psd'];
            echo $fullname.$email2.$newpassword; //print sucessfully

            $query2 = mysqli_query($link2, "INSERT INTO logins VALUES (NULL, $email2, $newpassword)");
            if ($query2) {
    echo "You have signed up successfully";
} else {

    echo "Error: ";   //query prints this statement
}
mysqli_close($link2);
        }   

}

?>

Here's my database Structure Db structure

这是我的数据库结构Db结构

3 个解决方案

#1


0  

You have to first remember that you have provide only 10 Character for username and 8 characters for password.

您必须首先记住,您只为用户名提供了10个字符,为密码提供了8个字符。

Even though if it is a varchar it will allow only 10 Charterers for Username and 8 Characters for Password and above that if you enter i am damp sure it will show you error wile inserting into the database.

即使它是一个varchar它只允许10个Charterers用户名和8个字符用于密码及以上,如果你输入我很潮,确定它会显示你插入数据库的错误。

Ensure updating or changing of the values that you provide for username and password in the database.

确保更新或更改您在数据库中为用户名和密码提供的值。

Note: By Chance if the user provided 11 Character for username and 8 Character for password too it will not be entering into the DB.

注意:如果用户为用户名提供了11个字符而密码也提供了8个字符,那么它将无法进入数据库。

Cross Check: Try putting echo to the statement and exit the loop after that and you directly put the echoed query in MYSQL so that you can find the Error very Easy and rectify it as per the requirement you need.

交叉检查:尝试将echo放回语句并在此之后退出循环,然后直接将回显的查询放在MYSQL中,这样您就可以找到错误非常简单并根据您的需求进行纠正。

And your query need to altered like this considering the id as auto-increment.

考虑到id为自动增量,您的查询需要像这样改变。

$query2 = mysqli_query($link2, "INSERT INTO logins(`username,password`) VALUES ('".$email2."', '".$newpassword."')");

Problem wasn't in the number of characters. But it was in the query.

问题不在于字符数。但它在查询中。

$query2 = mysqli_query($link2, "INSERT INTO logins(`username,password`) VALUES ('".$email2."', '".$newpassword."')"); 

didn't worked. But replacing it with,

没用。但取而代之的是,

$query = "INSERT INTO logins(username,password) VALUES ('".$email2."', '".$newpassword."')";
$query2 = mysqli_query($link2, $query);

worked for me! Thanks everyone who replied.

为我工作!谢谢所有回复的人。

#2


0  

Try this if Null value is for you id (auto-increment) then you don't want to specify it leave it blank. just like this

如果Null值是您的id(自动增量),请尝试此操作,然后您不想指定它,请将其留空。像这样

 $query2 = mysqli_query($link2, "INSERT INTO logins(username,password) VALUES ($email2, $newpassword)");

#3


0  

Try with:

Insert into logins (Id,email,password) values (NULL, ....

Assuming your names fields are "Id", "email", "password", etc.

假设您的姓名字段是“Id”,“email”,“password”等。

#1


0  

You have to first remember that you have provide only 10 Character for username and 8 characters for password.

您必须首先记住,您只为用户名提供了10个字符,为密码提供了8个字符。

Even though if it is a varchar it will allow only 10 Charterers for Username and 8 Characters for Password and above that if you enter i am damp sure it will show you error wile inserting into the database.

即使它是一个varchar它只允许10个Charterers用户名和8个字符用于密码及以上,如果你输入我很潮,确定它会显示你插入数据库的错误。

Ensure updating or changing of the values that you provide for username and password in the database.

确保更新或更改您在数据库中为用户名和密码提供的值。

Note: By Chance if the user provided 11 Character for username and 8 Character for password too it will not be entering into the DB.

注意:如果用户为用户名提供了11个字符而密码也提供了8个字符,那么它将无法进入数据库。

Cross Check: Try putting echo to the statement and exit the loop after that and you directly put the echoed query in MYSQL so that you can find the Error very Easy and rectify it as per the requirement you need.

交叉检查:尝试将echo放回语句并在此之后退出循环,然后直接将回显的查询放在MYSQL中,这样您就可以找到错误非常简单并根据您的需求进行纠正。

And your query need to altered like this considering the id as auto-increment.

考虑到id为自动增量,您的查询需要像这样改变。

$query2 = mysqli_query($link2, "INSERT INTO logins(`username,password`) VALUES ('".$email2."', '".$newpassword."')");

Problem wasn't in the number of characters. But it was in the query.

问题不在于字符数。但它在查询中。

$query2 = mysqli_query($link2, "INSERT INTO logins(`username,password`) VALUES ('".$email2."', '".$newpassword."')"); 

didn't worked. But replacing it with,

没用。但取而代之的是,

$query = "INSERT INTO logins(username,password) VALUES ('".$email2."', '".$newpassword."')";
$query2 = mysqli_query($link2, $query);

worked for me! Thanks everyone who replied.

为我工作!谢谢所有回复的人。

#2


0  

Try this if Null value is for you id (auto-increment) then you don't want to specify it leave it blank. just like this

如果Null值是您的id(自动增量),请尝试此操作,然后您不想指定它,请将其留空。像这样

 $query2 = mysqli_query($link2, "INSERT INTO logins(username,password) VALUES ($email2, $newpassword)");

#3


0  

Try with:

Insert into logins (Id,email,password) values (NULL, ....

Assuming your names fields are "Id", "email", "password", etc.

假设您的姓名字段是“Id”,“email”,“password”等。