我一直試圖讓我的HTML表單提交到指定的數據庫。我已經嘗試了我所知道的一切,但仍然沒有結果,我似乎無法得到錯誤。我的HTML數據沒有顯示在數據庫中
HTML表單
<form action = "connect.php" method = "post">
<br>
<br>
<br>
<h5 style ="color:White;" style="font-family:verdana" align = "center"><font size = "2">
<fieldset >
<legend>Personal information:</legend>
First name: <br>
<input type = "text" name ="firstname">
<br>
Last name: <br>
<input type = "text" name ="lastname"><br>
Username: <br>
<input type = "text" name = "username"><br>
Password <br>
<input type = "password" name ="password"><br>
School <br>
<input type = "text" name ="school"><br>
Department <br>
<input type = "text" name ="department"><br>
Year Of Study <br>
<input type = "text" name ="studyYear"><br>
Email <br>
<input type = "text" name ="email"><br>
Phone number <br>
<input type = "text" name ="phoneNumber"><br><br>
Gender <br>
<input type = "radio" name = "gender" value ="male">Male<br>
<input type = "radio" name = "gender" value ="female">Female<br>
<input type = "radio" name = "gender" value ="male">Other<br>
<br><br>
<input type ="submit" value ="Insert">
</h5>
</fieldset>
</h5>
</form>
PHP CODE
<?php
// Connect to localhost
$connect = mysqli_connect('localhost', 'root', '', 'sigma');
if(!$connect) {
echo("Didn\'t work ". mysqli_error());
}
// Get values from the form
$ID = $_POST['UserID'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
$school = $_POST['school'];
$dept = $_POST['department'];
$studyYear = $_POST['studyYear'];
$email = $_POST['email'];
$phone = $_POST['phoneNumber'];
// SQL query to insert the data collected from the form into the database.
$sql = mysqli_query ($connect, 'INSERT INTO users (firstname, lastname, username, password,
school, department, studyYear, email, phoneNumber)
VALUES ("'.$firstname.'", "'.$lastname.'", "'.$username.'","'.$password.'",
"'.$school.'", "'.$dept.'", "'.$studyYear.'", "'.$email.'", '.$phone.')');
if ($sql)
{
echo 'Inserted';
}
else
{
echo 'Not Inserted';
}
mysqli_close($connect);
?>
請添加您的PHP代碼。 –
你得到了什麼錯誤/錯誤?你確定PHP錯誤已啓用? – VSG24
@ShudhanshShekhar其下面的HTML表單代碼正下方非常感謝你 – Delalixx