我在使用PHP将数据插入mysql数据库时出现问题,这是我的代码:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/style.css">
<title></title>
</head>
<body>
<div id="container">
<div class="login">
<form method="post" action="login.php">
<table>
<tr>
<td><h1>E-mail</h1></td>
<td><h1>Password</h1></td>
</tr>
<tr>
<td><input type="text" name="login_email" id="login_email"></td>
<td><input type="password" name="login_password" id="login_password"></td>
<td><input type="submit" name="submit" id="login" value="Login"></td>
</tr>
<tr>
<td colspan="3"><?php if(isset($_GET['message'])){ echo "<h2>"
.$_GET['message']. "</h2>"; } ?></td>
</tr>
</table>
</form>
</div>
<div class="form">
<form method="post" action="index.php">
<table>
<tr>
<td colspan="2"><?php if(isset($successful)){ echo $successful; } ?></td>
</tr>
<tr>
<td><input type="text" name="names" id="names" placeholder="First Name" value="<?php if(isset($_POST['names'])){echo $_POST['names'];} ?>"></td>
<td><input type="text" name="surname" id="surname" placeholder="Last Name" value="<?php if(isset($_POST['surname'])){echo $_POST['surname'];} ?>"></td>
</tr>
<tr>
<td><?php if(isset($errors['name'])){echo "<h2>" .$errors['name']. "</h2>"; } ?></td>
<td><?php if(isset($errors['surname'])){echo "<h2>" .$errors['surname']. "</h2>"; } ?></td>
</tr>
<tr">
<td colspan="2"><input type="text" name="email" id="email" placeholder="E-mail Address" value="<?php if(isset($_POST['email'])){echo $_POST['email'];} ?>"></td>
</tr>
<tr>
<td colspan="2"><?php if(isset($errors['email'])){echo "<h2>" .$errors['email']. "</h2>"; } ?></td>
</tr>
<tr>
<td colspan="2"><input type="password" name="password" id="pw" placeholder="Password"></td>
</tr>
<tr>
<td colspan="2"><?php if(isset($errors['password'])){echo "<h2>" .$errors['password']. "</h2>"; } ?></td>
</tr>
<tr>
<td colspan="2"><input type="password" name="confirm_password" id="cpw" placeholder="Confirm Password">
</tr>
<tr>
<td colspan="2"><?php if(isset($errors['confirm_password'])){echo "<h2>" .$errors['confirm_password']. "</h2>"; } ?></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Sign Up"></td>
</tr>
</table>
</form>
</div>
<div class="footer"></div>
</div>
<?php
$con = mysqli_connect("localhost","root","","form_validation");
$name1 = $_POST['name'];
$surname1 = $_POST['surname']; //this is line 32 and so on...
$email = $_POST['email'];
$password = hash('sha256', $_POST['password']);
function createSalt()
{
$string = md5(uniqid(rand(), true));
return substr($string, 0, 3);
}
$salt = createSalt();
$password = hash('sha256', $salt . $password);
$search_query = mysqli_query($con, "SELECT * FROM members WHERE email = '$email'");
$num_row = mysqli_num_rows($search_query);
if ($num_row >= 1) {
$errors['email'] = "Email address is unavailable.";
} else {
$sql = "INSERT INTO members(`fname`, `lname`, `email`, `salt`, `password`)`VALUES ('$name1', '$surname1', '$email', '$salt', '$password')"`;
$query = mysqli_query($con, $sql);
$_POST['name'] = '';
$_POST['surname'] = '';
$_POST['email'] = '';
$successful = "<h3> You are successfully registered.</h3>";
}
?>
</body>
</html>
这里是错误:
注意:未定义的索引:第70行的C:\ wamp64 \ www \ form_validation \ index.php中的名称
注意:未定义的索引:第71行的C:\ wamp64 \ www \ form_validation \ index.php中的姓氏
注意:未定义的索引:第72行的C:\ wamp64 \ www \ form_validation \ index.php中的电子邮件
注意:未定义的索引:第73行的C:\ wamp64 \ www \ form_validation \ index.php中的密码