問題標題顯示我使用PHP和SQL創建註冊表單。無論何時點擊註冊按鈕,我都會在表單中的所有變量上得到一個未定義的變量錯誤,也不會在數據庫中輸入任何內容。如果您可以提出任何建議,請將我的頭髮拉出。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>
任何幫助真的很感激,謝謝。
爲什麼不只是綁定到'POST'變量? – Kermit 2013-02-23 18:14:01