为新手问题道歉,我一直在努力让我的插件工作。
$ qry的var_dump返回正确的值,但$ insert的var_dump返回false布尔值。因此,我没有将任何值插入到我的表中,也无法理解为什么。
非常感谢这里的指针。提前谢谢。
<?php
$host = 'localhost';
$user = 'tim_williams';
$pass = 'baroness';
$db = 'php_db05';
$link = mysqli_connect($host, $user, $pass, $db);
if(!$link) {
die("Database connection failed");
}
function clean_form($data) {
global $link;
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
$data = mysqli_real_escape_string($link, $data);
return $data;
}
if(isset($_POST['submit'])) {
$fname = clean_form($_POST['fname']);
$lname = clean_form($_POST['lname']);
$email = clean_form($_POST['email']);
$password1 = clean_form($_POST['password1']);
$password2 = clean_form($_POST['password2']);
$username = strtolower($fname.substr($lname,0,1));
$dateTime = date('Y-m-d g:i:s',time());
if ($fname && $lname && $email && $password1 && $password2 && $username && $dateTime) {
$qry = "INSERT INTO registeredusers ('UserID', 'UserName', 'FirstName', 'Surname', 'EmailAddress', 'Password')
VALUES ('','$username','$fname', '$lname', '$email', '$password1','$dateTime')";
$insert = mysqli_query($link, $qry);
}
}
var_dump($insert);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./css/layout.css" media="screen" type="text/css">
<link rel="stylesheet" href="./css/menu.css" media="screen" type="text/css">
<meta charset="utf-8">
<title>New User Registration</title>
</head>
<body>
<div class="holder">
<div class="header"></div>
<div class="navbar">
<nav>
<ul>
<li><a href="/uni/uni_log_reg/mysql-project-users-login.php">Login</a></li>
<li><a href="/uni/uni_log_reg/mysql-project-users-add.php">Register</a></li>
</ul>
</nav>
</div>
<div class="content">
<div class="pageheading">
<h1>New Users</h1>
</div>
<div class="contentleft">
<h2>Welcome to my site</h2><br />
<h6>Please register an account with us to access main content and more.</h6>
</div>
<div class="contentright">
<form class="registerform" action="" method="post">
<input class="styletxtfield" type="text" name="fname" placeholder="First Name" value=""><input class="styletxtfield forminput" type="text" name="lname" placeholder="Last Name" value=""><br /><br />
<input class="styletxtfield" type="text" name="email" placeholder="Email address" value=""><br /><br />
<input class="styletxtfield" type="text" name="password1" placeholder="Password" value=""><input class="styletxtfield forminput" type="text" name="password2" placeholder="Confirm Password" value=""><br /><br />
<input type="submit" name="submit" value="submit">
</form>
</div>
</div>
<div class="footer"></div>
</div>
</body>
</html>