问题描述
我遇到一个小问题。我想按按钮创建数据库时,可以使用文本输入来命名它。我想在php中做到这一点。如果有人可以帮助我,我将非常感激
index.php:
require("secret.php");
require("getDatabases.php");
$conn = new PDO($servername,$username,$password);
$databases = getDatabases($conn);
// $createDB = create_db($conn,$name);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>phpMyAdmin</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"/>
</head>
<body>
<!-- list databases-->
<div class="list-group">
<?php
foreach($databases as $data){
echo "<button type=button class=list-group-item list-group-item-action>". htmlspecialchars($data)."</button>";
}
?>
</div>
<!-- to create database -->
<form method="post" action="./database/createDB.php">
<input type="text" placeholder="Create your database"><br>
<input type="submit" name="submit" value="Create my DB">
</form>
</body>
</html>
createDB.php:
function createDB($pdo,$name)
{
$create = `CREATE DATABASE $name`;
$pdo->exec($create);
}
if(isset($_POST['submit']))
{
createDB();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)