我想弄清楚如何從用戶輸入從使用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;你真的應該嘗試一些東西。沒有理由不能在網上找到這個教程;有很多,如果不是數千。由於查詢中缺少參數,我發現問題太寬泛且不清楚。 –