我正在尝试将一系列文本字段提交到我预先存在的mysql数据库中。 我正在使用XAMPP,并通过phpmyadmin创建了一个数据库,供我们使用。
这是我到目前为止所做的:
编辑:我已经解决了未定义的索引通知...唯一的问题是,phpmyadmin上没有更新文本字段的值。
<?php
$mysqli = mysqli_connect("localhost","tmmorrow","letmein","testDB");
$sql = "SELECT firstname, lastname FROM members WHERE email =
'".filter_input(INPUT_POST,'email'). "' AND password = "."PASSWORD('".filter_input(INPUT_POST,'password')."');";
$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));
$fName= mysqli_real_escape_string($mysqli, isset($_POST['firstname']) ? $_POST['firstname'] : '');
$lName= mysqli_real_escape_string($mysqli, isset($_POST['lastname']) ? $_POST['lastname'] : '');
$email= mysqli_real_escape_string($mysqli, isset($_POST['email']) ? $_POST['email'] : '');
$passwd= mysqli_real_escape_string($mysqli, isset($_POST['password']) ? $_POST['password'] : '');
$age= mysqli_real_escape_string($mysqli, isset($_POST['age']) ? $_POST['age'] : '');
$gender= mysqli_real_escape_string($mysqli, isset($_POST['gender']) ? $_POST['gender'] : '');
$start= date('Y-m-d');
$mysql= "INSERT INTO members (firstname, lastname, email, password, age, gender, startdate)
VALUES ('$fName', '$lName', '$email', '$passwd', '$age', '$gender', '$start')";
/*$display=
//if(email is already in database)
"<p><h3>Your email address has already been used!</br>
Please use a different email for a new account.</h3></p>
<p><a href=\"applyaccount.html\">Click here to go back to the <b>registration</b> page.</a></p>";
//else show this
"<p><h3>Your account has been created!</h3></p></br>
<p><a href=\"userlogin.html\">Click here to go back to the <b>login</b> page.</a></p>";
*/
?>
<html>
<head>
<meta charset="utf-8">
<title>User signup</title>
</head>
<body>
<?php //echo "$display"; ?>
<p><a href="applyaccount.html"><b>registration</b> page</a></p>
<p><a href="userlogin.html"><b>login</b> page</a></p>
</body>
</html>
*******two seperate files. applyaccount.html & applyaccount.php*******
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>User signup</title>
</head>
<body>
<h1>Sign up for your account here!</h1>
<form method="post" action="applyaccount.php">
<p><strong>First Name:</strong>
<input type="text" name="firstname"></p>
<p><strong>Last Name:</strong>
<input type="text" name="lastname"></p>
<p><strong>Email:</strong>
<input type="text" name="email"></p>
<p><strong>Password:</strong>
<input type="password" name="password"></p>
<p><strong>Age:</strong>
<input type="text" name="age"></p>
<p><strong>Gender:</strong>
<input type="text" name="gender"></p>
<p><input type="submit" name="submit" value="Sign up"></p>
</form>
<p><a href="userlogin.html">Return to the login page</a></p>
</body>
</html>
非常感谢任何帮助。 谢谢!