我有一個數據庫,其中有一個表Users
和6列 (userID (primary), prenume, nume, nicknamee, parola, tara
) 我想開發一個用戶註冊系統。目前,我只希望用戶輸入用戶名/暱稱和密碼。問題是,當我按提交時,證書不會被插入到數據庫中。有人可以幫我嗎?PHP註冊表格沒有插入憑據到數據庫中
這裏是我的代碼:
<html>
<?php
$servername = hhhhh;
$username = hiuhiuhiuh;
$password = theseAreSecret;
$dbname = shhhh;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully\n";
?>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Campfire</title>
<link rel="stylesheet" href="">
</head>
<body>
<form method="post">
Username:
<input type="text" name="nicknamee" value="Username"><br>
Password:
<input type="password" name="password" value="Password"><br>
<input type="submit" name="Submit1" value="submit">
<?php
if (isset($_POST['Submit1'])) {
$sql = "INSERT INTO Users (userID, prenume, nume, nicknamee, parola, tara)
VALUES (5, 'John', 'Snow', '$_POST[nicknamee]', '$_POST[password]', 'Romania')";}
?>
</form>
</body>
<?php
// Print everything out
$result = $conn->query("SHOW TABLES");
while ($row = $result->fetch_row()){
$table = $row[0];
echo '<h3>',$table,'</h3>';
$result1 = $conn->query("SELECT * FROM $table");
if($result1) {
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
$column = $conn->query("SHOW COLUMNS FROM $table");
echo '<tr>';
while($row3 = $column->fetch_row()) {
echo '<th>'.$row3[0].'</th>';
}
echo '</tr>';
while($row2 = $result1->fetch_row()) {
echo '<tr>';
foreach($row2 as $key=>$value) {
echo '<td>',$value,'</td>';
}
echo '</tr>';
}
echo '</table><br />';
}
}
echo '<br>';echo '<br>';echo '<br>';echo '<br>';
$conn->close();
?>
</html>
順便說一下,這個註冊表格很容易被sql注入。你可以在這裏閱讀更多關於它的信息:https://www.owasp.org/index.php/SQL_Injection – Arin
你的PHP代碼的第一行,並且已經有一個語法錯誤。正如阿林所說,犯了錯誤,它會幫助你很多。 ;) – Twinfriends