正如标题所示,我正在使用 PHP 和 SQL 创建一个注册表单。每当我单击注册按钮时,表格中的所有变量都会出现未定义的变量错误,数据库中也没有输入任何内容。请如果你能提出任何建议,我正在拔头发。
这是表单提交到的页面:
<?php
include('dbconfig.php');
?>
<?php
echo $_GET["FirstName"];
?>
<?php
$db = new PDO('mysql:host=localhost;dbname=mydatabase;', 'root', '');
$firstname = $_POST['FirstName'];
$lastname = $_POST['LastName'];
$username = $_POST['username' ];
$password = $_POST['Password'];
$email = $_POST['Email'];
$startdate = $_POST['StartDate'];
$year = $_POST['Year'];
$password = md5($password);
$sql = "INSERT into supervisor (FirstName, LastName, UserName, Password, Email,
Company) VALUES (:FirstName, :LastName, :UserName, :Password, :Email)";
$statement = $db->prepare($sql);
$params = array(
':FirstName' => $firstname,
':LastName' => $lastname,
':Password' => $password,
':Email' => $email,
':StartDate' => $startdate,
':Year' => $year,
':Company' => $company
);
dbconfig 文件:
<?php
$config['db'] = array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'mydatabase',
);
$db = new PDO('mysql:host='. $config['db']['host'] .';dbname='. $config['db']
['dbname'], $config['db']['username'], $config['db']['password']);
?>
最后是注册php文件(只是表格):
<div class="container">
<form id="regform" class="form-signin" action='staffRegister.php' method='Post'
onsubmit="return validateForm()"/>
<img src="logo.png" width="160" height="50"> <h2 class="form-signin-heading">Staff
Registration</h2>
<div>
<label for="name">First Name: </label>
<input id="fname" name="name" type="text" class="input-
block-level" maxlength="35" onFocus="if(this.value=='name')this.value='';" onblur =
"checkField(this)"/>
<span id="Alpha" style="display:none;">Please use letters
only.</span>
</div>
<div>
<label for="name">Last Name: </label>
<input id="lname" name="name" type="text" class="input-
block-level" maxlength="35" onFocus="if(this.value=='name')this.value='';" onblur =
"checkField1(this)"/>
<span id="Alpha2" style="display:none;">Please use letters
only.</span>
</div>
<div>
<label for="name">UserName: </label>
<input id="username" name="name" type="text" class="input-
block-level" maxlength="12" />
</div>
<div>
<label for="email">E-mail Ad:</label>
<input id="email" placeholder="@kent.ac.uk"name="Email"
type="text" class="input-block-level" onchange="return validateEmail();"/></br>
<span id="spanEmail" style="display:none;">Please use your
Kent Email.</span>
</div>
<div>
<label for="pass1">Password:</label>
<input id="pass1" name="pass1" type="password"
class="input-block-level" maxlength="12" />
<span id="pass1Info">At least 6 characters: letters,
numbers and '_'</span>
</div>
<div>
<center><input type='Submit' name='Submit' value="Register" class="btn btn-
primary"/ > </input></center>
</form>
任何帮助都非常感谢,谢谢。