我想弄清楚如何从用户输入从使用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'])并存储到变量中,第二步在sql插入查询中传递这些变量 –
Lee;你真的应该尝试一些东西。没有理由不能在网上找到这个教程;有很多,如果不是数千。由于查询中缺少参数,我发现问题太宽泛且不清楚。 –