无法将php密码字段上传到phpmyAdmin

时间:2018-09-13 06:41:47

标签: javascript php css html5 phpmyadmin

我有一个HTML表单,可以接受用户的名字,姓氏,用户名和密码,并且我将值上传到本地的 phpMyAdmin ,但是我无法上传密码字段进入数据库。

这是我的HTML代码

<input type="text" name="first" required placeholder="John*">
<input type="text" name="last" required placeholder="Doe*">
<input type="text" name="username" id="vname" placeholder="jondoe11*" />
<input type="password" name="pass" id="vpassword" placeholder="*****" />

和我的php文件

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "credentials";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {      
    die("Connection failed: ");  
}  else
{    echo "connnected";  }

$first = $_POST['first'];
$last = $_POST['last'];
$user = $_POST['username'];
$password = $_POST['pass'];


$sql =$conn->prepare('INSERT INTO users (username, password, first, last) values(?,?,?,?)');
$sql->bind_param('ssss', $user,$password,$first,$last);
$val = $sql->execute();
?>

我可以成功输入除密码字段以外的所有值。 请帮助

1 个答案:

答案 0 :(得分:0)

您拥有用于数据库连接的变量$password,并且还为数据传递访问了相同的变量。我将数据变量更改为$user_password。希望这对您有用。

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "credentials";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {      
    die("Connection failed: ");  
}  else
{    echo "connnected";  }

$first = $_POST['first'];
$last = $_POST['last'];
$user = $_POST['username'];
$user_password = $_POST['pass'];


$sql =$conn->prepare('INSERT INTO users (username, password, first, last) values(?,?,?,?)');
$sql->bind_param('ssss', $user,$user_password,$first,$last);
$val = $sql->execute();
?>