这是我的HTML表单:
<form action="PHP/Signup.php" method="POST">
<input type="text" name="FirstName" placeholder="Firstname" required="true"><br><br>
<input type="text" name="MiddelName" placeholder="Middelname"><br><br>
<input type="text" name="LastName" placeholder="Lastname" required="true"><br><br>
<input type="text" name="Username" placeholder="Username" required="true"><br><br>
<input type="password" name="Password" placeholder="Password" required="true"><br><br>
<input type="email" name="Email" placeholder="Email address" required="true"><br><br>
<input type="text" name="Phone" placeholder="Phone number"><br><br>
<input type="text" name="Class" placeholder="Enter your class code eks. 2MKA" required="true"><br><br>
<button type="submit">SIGN UP</button>
</form>
这是我的PHP代码(PHP / Signup.php):
<?php
session_start();
include 'PHP/ConfigMamp.php';
$FirstName = $_POST['FirstName'];
$MiddelName = $_POST['MiddelName'];
$LastName = $_POST['LastName'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Class = $_POST['Class'];
//Test to see if the form acctully gets posted
//echo $FirstName. "<br>";
//echo $MiddelName. "<br>";
//echo $LastName. "<br>";
//echo $Username. "<br>";
//echo $Password. "<br>";
//echo $Email. "<br>";
//echo $Phone. "<br>";
//echo $Class. "<br>";
$sql = "INSERT INTO Users
(FirstName, MiddelName, LastName, Username, Password, Email, Phone, Class) VALUES
('$FirstName', '$MiddelName', '$LastName', '$Username', '$Password', '$Email', '$Phone', '$Class')";
$result = mysqli_query($conn, $sql);
header("Location: ../index.php");
?>
我注释掉的行是测试数据是否从一个页面发送到另一个页面,我确实收到了数据但是当我尝试将其发送到sql时,它没有达到或没有达到得救了。有人能帮助我吗?
这是&#34; PHP / ConfigMamp.php&#34;文件:
<?php
$Server = "localhost";
$Username = "root";
$Password = "root";
$Database = "BjerkeWeb";
// Create connection
$conn = mysqli_connect($Server, $Username, $Password, $Database);
// Check connection
// Remove mysqli_connect_error() after testing, leaves vulnerability to sql injection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "<a style='
color: green;
position: absolute;
bottom: 40px;
right: 40px;
'>Connected successfully to the database</a>";
?>
答案 0 :(得分:0)
您Signup.php
中包含的配置文件位于同一目录PHP/
这可能有效
include ('ConfigMamp.php');
注意:不推荐使用mysql,你可能会得到sql注入。您必须使用PDO
或mysqli