尝试将表单数据发送到数据库,似乎正在这样做但我检查数据库并没有出现任何内容。谁能告诉我哪里出错了?除了添加我自己的变量之外,我几乎遵循了Youtube教程,但不太确定我哪里出错了。
HTML
<!doctype html>
<html>
<head>
<title>Registration Page</title>
<link rel="stylesheet" href="http://localhost/loginreg/css/styles.css" />
</head>
<body>
<div id="wrapper">
<div id="formDiv">
<form method="POST" action="registration/connect.php">
<label>First Name:</label><br>
<input type="text" name="fname" /> <br/><br/>
<label>Last Name:</label><br>
<input type="text" name="lname" /> <br/><br/>
<label>Email:</label><br>
<input type="text" name="email" /> <br/><br/>
<label>Password:</label><br>
<input type="password" name="password" /> <br/><br/>
<label>Confirm Password:</label><br>
<input type="password" name="cpassword" /> <br/><br/>
<input type="submit" name="submit" />
</form>
</div>
</div>
</body>
</html>
PHP
<?php
$con = mysqli_connect("127.0.0.1","root","");
if(!$con)
{
echo 'Not conneced to server';
}
if(!mysqli_select_db($con,'registration'))
{
echo 'Database not selected';
}
$firstName = $_POST['fname'];
$lastName = $_POST['lname'];
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "INSERT INTO users (firstName,lastName,email,password) VALUES ('$firstName','$lastName','$email','$password')";
header("refresh:2; url=http://localhost/loginreg/index.html");
?>
答案 0 :(得分:-1)
在$sql
变量之后,添加以下内容:
if ($conn->query($sql) === TRUE)
{
echo 'success';
}
就像Chris85所说的那样,这不是完全安全的,并且会让你打开SQL注入。