タイトルが示すように、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>
どんな助けでも本当に感謝します、ありがとう。