Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php数据库数据保存_Php_Mysql_Database - Fatal编程技术网

php数据库数据保存

php数据库数据保存,php,mysql,database,Php,Mysql,Database,我正在用php制作一个注册表单,但当我点击注册按钮时,它会在电子邮件和密码字段中保存1,1,而不是给定的电子邮件和密码 <?php include("connection.php") ?> <?php $email=isset($_POST['email']); $password=isset($_POST['password']); if(isset($_POST['register'])) { $q= "insert into admin (email, p

我正在用php制作一个注册表单,但当我点击注册按钮时,它会在电子邮件和密码字段中保存1,1,而不是给定的电子邮件和密码

  <?php
include("connection.php")
?>
<?php

$email=isset($_POST['email']);
$password=isset($_POST['password']);

if(isset($_POST['register']))
{
    $q= "insert into admin (email, password) values ('$email', '$password')";
    $qr=mysqli_query($con, $q);
    if($qr)
    {
        echo "data added sucessfully";
    }
    else
    {
        die();
    }
}

?>

<!DOCTYPE html>
<html>
<head>
    <title>Log in</title>
</head>
<body>
<form method="post" action="">
<input type="email" name="email">
<br>
<input type="password" name="password">
<br>
<button type="submit" name="register" value="register">register</button>
</form>
</body>
</html>

Isset函数返回布尔值,请尝试:

if(isset($_POST['email'])){
    $email=$_POST['email'];
}
if(isset($_POST['password'])){
    $password=$_POST['password'];
}

它之所以在数据库中输入
1
,是因为POST数组的
isset()

旁注:您可能打算使用三元运算符

RTM:
bool-isset(mixed$var[,mixed$…])
返回布尔值

$email=isset($_POST['email']);
$password=isset($_POST['password']);
您需要删除
isset()

然后检查它们是否不是空的

if(!empty($_POST['email']) && !empty($_POST['password']) )
并放置在
if(isset($_POST['register']){…}

我不知道为什么要将代码嵌入textarea。
编辑:我看到您在编辑中删除了它

还要确保列类型能够存储字符串而不是整数,并且足够长以容纳存储的数据

您当前的代码对用户开放。使用,或与


密码

我还注意到,您可能正在以纯文本形式存储密码。如果您打算继续使用此功能,则不建议使用此功能

使用以下选项之一:

  • PHP5.5的函数
  • 兼容性包(如果PHP<5.5)
其他链接:

关于列长度的重要旁注:

如果您决定使用
password\u hash()
或crypt,请务必注意,如果当前密码列的长度小于60,则需要将其更改为60(或更高)。手册建议长度为255

您需要更改列的长度,并使用新的哈希重新开始,以使其生效。否则,MySQL将以静默方式失败


脚注:

您还应该检查查询中的错误

错误报告是另一个可以帮助您解决问题的方法


我想应该是下面这样

$email=isset($email)$电子邮件:“
$password=isset($password)$密码:“

,isset函数返回一个布尔值,更改为if(isset($\u POST['email']){$email=$\u POST['email'];}编辑:发布为应答请使用PHP处理密码安全性。如果您使用的PHP版本低于5.5,您可以使用
密码\u hash()
。或者您可以使用十进制运算符:
$email=(isset($\u POST['email'])?$\u POST['email']:“”),因为未设置所有字段时会发生什么?未定义变量
if(!empty($_POST['email']) && !empty($_POST['password']) )