PHPを使用してHTMLフォームからユーザー入力からデータベースに情報を挿入する方法を理解しようとしていますが、100%確実ではありません。ユーザー入力を使用してPHPからユーザーデータを挿入する
ここに私が現在持っているものがあります。
HTML
<form id="playerForm" action="insert.php" method="post">
Player Name: <input type="text" value="playerName">
Player Race: <input type="text" value="playerRace">
Player Class: <input type="text" value="playerClass">
<button id="submit">Submit</button>
</form>
PHP
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
//create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
//check connection
if(!$conn){
die("Unable to connect to MySQL: " . mysqli_connect_error());
}
echo "connected successfully"."<br><br>";
//selects the different data types from the professions table
$sql = "INSERT INTO Player (PlayerName, PlayerRace, PlayerClass)
VALUES()";
$result = $conn->query($sql);
$conn->close();
正確な質問はありますか? –
最初のステップ:フォームの値($ _POST ['playerName'])をフェッチして変数に格納し、2番目のステップでこれらの変数をSQL挿入クエリに渡します。 –
Lee;あなたは本当に何かを試していたはずです。このためにWebでチュートリアルを見つけられなかった理由はありません。数千ではないにせよ、多くがあります。クエリーにパラメータがないと、質問があまりにも広く、不明瞭になることがあります。 –