Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.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 - Fatal编程技术网

Php 用户输入未存储在数据库中

Php 用户输入未存储在数据库中,php,mysql,Php,Mysql,我是php的初学者,我刚刚用php做了一个base64编码器和解码器。它工作正常,但我希望用户尝试使用的所有哈希都存储在数据库中。它没有显示任何语法错误,我也找不到任何奇怪的东西。 请帮帮我。 所有内容都在一个名为 index.php <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'base64'; $dbconn = mysql_connect($dbhost, $dbuser, $dbpass

我是php的初学者,我刚刚用php做了一个base64编码器和解码器。它工作正常,但我希望用户尝试使用的所有哈希都存储在数据库中。它没有显示任何语法错误,我也找不到任何奇怪的东西。 请帮帮我。 所有内容都在一个名为 index.php

 <?php

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'base64';

$dbconn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($db);
?>
<!DOCTYPE html>
<html>
<head>
    <title>Base64 Encoder and Decoder</title>
</head>
<body>
    <div class="spinner"></div>
    <div class="template">
    <h1>Base 64 Encoder</h1>
    <form method="POST" action="#">
        <input type="text" name="encode">
        <input type="submit" name="encodebtn">
    </form>
</body>
</html>
<br><br>
<!DOCTYPE html>
<html>
<head>
    <title>Base64 Encoder and Decoder</title>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
</head>
<body>
    <h1>Base 64 Decoder</h1>
    <form method="POST" action="#">
    <input type="text" name="decode">
    <input type="submit" name="decodebtn">
</form>
</div>
</body>
</html>
<br><br>
    <div class="panel panel-primary">
      <div class="panel-heading">
        Result
      </div>
      <div class="panel-body">
        <?php
if (isset($_POST['decodebtn'])) {
    $text = $_POST['decode'];
    $decodehash = base64_decode($text); 
    $encodehash = base64_encode($text);
    echo "Decoded Successfully: " . $decodehash;
    $query = ("INSERT INTO hashes (Encoded, Decoded) VALUES ('$encodehash', '$decodehash')");
}
if (isset($_POST['encodebtn'])) {
    $text = $_POST['encode'];
    $encodehash = base64_encode($text);
    $decodehash = base64_decode($text); 
    echo "Encoded Successfully: " . $encodehash;

}

?>
      </div>
    </div>
</div>
<style>
.panel {
margin-bottom: 20px;
background-color: #fff;
border: 1px solid transparent;
border-radius: 0px;
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.05);
width: 40%;
}
.panel-primary {
border-color: lightgreen !important;
}
.panel-heading {
background: lightgreen !important;
}

Base64编解码器
基64编码器


Base64编解码器 基64解码器

结果 你忘了

mysql_query($query,$dbcon);

将其保留在$query变量之后

用此代码替换您的代码

    <?php

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'base64';

$dbconn = new mysqli($dbhost,$dbuser,$dbpass,$db);

?>
<!DOCTYPE html>
<html>
<head>
    <title>Base64 Encoder and Decoder</title>
</head>
<body>
<div class="spinner"></div>
<div class="template">
    <h1>Base 64 Encoder</h1>
    <form method="POST" action="#">
        <input type="text" name="encode">
        <input type="submit" name="encodebtn">
    </form>
</body>
</html>
<br><br>
<!DOCTYPE html>
<html>
<head>
    <title>Base64 Encoder and Decoder</title>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
</head>
<body>
<h1>Base 64 Decoder</h1>
<form method="POST" action="#">
    <input type="text" name="decode">
    <input type="submit" name="decodebtn">
</form>
</div>
</body>
</html>
<br><br>
<div class="panel panel-primary">
    <div class="panel-heading">
        Result
    </div>
    <div class="panel-body">
        <?php
        if (isset($_POST['decodebtn'])) {
            $text = $_POST['decode'];
            $decodehash = base64_decode($text);
            $encodehash = base64_encode($text);
            echo "Decoded Successfully: " . $decodehash;
            $query = ("INSERT INTO hashes (Encoded, Decoded) VALUES ('$encodehash','$decodehash')");
            $dbconn->query($query);
        }
        if (isset($_POST['encodebtn'])) {
            $text = $_POST['encode'];
            $encodehash = base64_encode($text);
            $decodehash = base64_decode($text);
            echo "Encoded Successfully: " . $encodehash;

        }

        ?>
    </div>
</div>
</div>
<style>
    .panel {
        margin-bottom: 20px;
        background-color: #fff;
        border: 1px solid transparent;
        border-radius: 0px;
        -webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.05);
        width: 40%;
    }
    .panel-primary {
        border-color: lightgreen !important;
    }
    .panel-heading {
        background: lightgreen !important;
    }

Base64编解码器
基64编码器


Base64编解码器 基64解码器

结果
SQL注入警报-阅读PDO上的准备语句使用
mysqli\u*
函数,而不是
mysql\u*
函数投票为输入错误;您从未执行过查询。@FunkFortyNiner感谢它现在可以工作,不客气。