-1
我試圖學習真正基本的PHP/SQL,並且在詢問之前做過搜索,但對於我來說它們確實是非常複雜的示例。在進入數據庫之前檢查重複內容
所以這裏是一個基本的教程代碼,我使用和輕鬆編輯。
我可以添加到現有的代碼來檢查用戶名是否已經存在,所以我不再創建它?
<html>
<body>
<?php
// put your code here
$servername = "localhost"; //should be same for you
$username = "user"; //same here
$password = "password"; //your localhost root password
$db = "myDB"; //your database name
$conn = new mysqli($servername, $username, $password, $db);
if($conn->connect_error){
die("Connection failed".$conn->connect_error);
}else{
echo "Connected<br>";
}
$sql="INSERT INTO login (username, password)
VALUES
('$_POST[username]','$_POST[password]')";
echo "<br><br>Inserting into db: ";
if($conn->query($sql)==TRUE){ //try executing the query
echo "Query executed<br>";
}
else{
echo "Query did not execute<br>";
}
$conn-> close(); //close the connection to database
?>
</body>
</html>