我是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;
}
答案 0 :(得分:0)
你忘记了
HttpContext
在$ query变量之后键入它;
答案 1 :(得分:0)
用此代码替换您的代码
<?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;
}