<form method="post">
<input type="text" name="namedb" value="namedb">
<input type="submit" value="создать запись">
</form>
<?php
if ($_POST){
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "CREATE DATABASE IF NOT EXISTS Mydatabase";
$conn->query($sql);
$db_selected = $conn->select_db('Mydatabase');
$sql = "CREATE TABLE IF NOT EXISTS MyTable (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
login VARCHAR(30)
)";
if ($conn->query($sql) === TRUE) {
echo "Таблица MyTable успешно создана";
}
$sql = "INSERT INTO MyTable (login) VALUES ('{$_POST['namedb']}')";
if ($conn->query($sql) === TRUE) {
echo "<br>Записан следующий логин ".$_POST['namedb'];
}
$sql = "SELECT id,login FROM MyTable";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br>"."id: " . $row["id"]. " Логин: " . $row["login"]."<br>";
}
} else {
echo "0 results";
}
$conn->close();
}
?>
|