尝试从表单调用时出现Php错误

时间:2014-03-19 02:59:14

标签: php html database

<?php
extract($_REQUEST);

$FirstName = $_POST['firstname'];
$LastName = $_REQUEST['lastname'];
$dob = $_REQUEST['dob'];
$Email = $_REQUEST['email'];
$address = $_REQUEST['address'];
$pcode = $_REQUEST['pcode'];
$username = $_REQUEST['username'];
$Password = $_REQUEST['pwd'];
$Question= $_REQUEST["Question"];
$answer = $_REQUEST['answer'];
$player = $_REQUEST['player'];


if ($player == "Annadale Player") {
   if ( isset($FirstName) && isset($LastName) && isset($dob) && isset($Email) && isset($address) && isset($pcode) && isset($username) && isset($Password) && isset($Question) && isset($answer) && isset($player)) {
    mysql_connect('localhost', 'root', '');
    mysql_select_db( "fypannadale" );

mysql_query( "INSERT INTO members (MemberID,FirstName,LastName,dob,Email,Address,PostCode,UserName,Password,Question,Answer,Anndale_Relationship)VALUES('$FirstName','$LastName', '$dob','$Email','$Address','$Postcode','$UserName','$Password','$Question','$answer','$player')" );

    echo " $FirstName $LastName has been registered with the F1 Project website";
 } }
else
 {  if ( isset($FirstName) && isset($LastName) && isset($dob) && isset($Email) && isset($address) && isset($pcode) && isset($username) && isset($Password) && isset($Question) && isset($answer) && isset($player)){
    mysql_connect('localhost', 'root', '');
    mysql_select_db( "FYPannadale" );

mysql_query( "INSERT INTO members (MemberID,FirstName,LastName,dob,Email,Address,PostCode,UserName,Password,Question,Answer,Anndale_Relationship)VALUES('$FirstName','$LastName', '$dob','$Email','$Address','$Postcode','$UserName','$Password','$Question','$Answer','$player')" );

    echo " sent";

} }


 <script type="text/javascript">
function CloseWindow() {
    window.close();
    window.opener.location.reload();
}
</script>

</head>

<body>

 <div class="colmask" id="colmask"><h3>To register to the Annadale Hockey website and forum, please complete your details below. </h3>
 <p>
 <form id='register' action='<?= $_SERVER['PHP_SELF'] ?>' method='post' onsubmit="">
 <LABEL for="firstname">First Name: </LABEL>
          <INPUT type="text" name="firstname" size="20">
 <LABEL for="lastname">Last Name: </LABEL>
          <INPUT type="text" name="lastname" size="20"><BR><br>
 Date of Birth (DOB): <input type="date" name="dob"> <LABEL for="email">   Email: </LABEL>
          <INPUT type="email" name="email" size="30"><br>


  <br><LABEL for="address">Address:</LABEL> <input type="text" name="address" size="50">
   <LABEL for="postcode">   Postcode:</LABEL> <input type="text" name="pcode" size="10"><br><br>
  <LABEL for="Username">Username:</LABEL> <input type="text" name="username"><br><br>
  <LABEL for="password">Password:</LABEL> <input type="password" name="pwd"><br><br>
  <LABEL for="recovery"> Recovery Question: </LABEL><input list="Questions" name="Questions"size="40">

 <datalist id="Questions">
<option value="Who is your Favourite Annadale Player?">
<option value="What is the name of your Pet?">
<option value="What position do you play?">
<option value="What is your mums maiden name?">
<option value="Who inspires you?">
 </datalist> <LABEL for="answer"> Answer: </LABEL>
          <INPUT type="text" id="answer"><br><br>
<LABEL for="Player">Which of the following associates you to Annadale: </LABEL><br>

<input type="radio" name="player" value="Annadale Player">Annadale Player
<input type="radio" name="player" value="Supporter">Supporter
  <input type="radio" name="player" value="Committee Member">Committee Member
<input type="radio" name="player" value="team manager">Team Manager
<input type="radio" name="player" value="Other">Other<br><br>

 <LABEL for="mobile">Can you please submit your mobile number: </LABEL><input     type="text" name="mobile" size="20"><br><br>
 <input type='hidden' name='submitted' id='submitted' value='1'/>
 <INPUT type="submit" value="Submit" onclick="javascript: return CloseWindow();">          
 <INPUT type="reset"></p>
 </form></div>
 </body>
 </html>

我正在尝试从表单中提取信息并将其实现到数据库中我已经创建了一个if语句,我想在将来编辑更多,以便如果选择某种类型的关联,它将发送额外数据到别的地方。 我在尝试运行时遇到了很多PHP错误,我的代码哪里出错?

我得到的错误是; 注意:未定义的索引:第5行的C:\ wamp \ www \ FinalProject \ Webpages \ Registration.php中的firstname 调用堆栈

时间记忆功能位置

1 0.0017 266096 {main}().. \ Registration.php:0

我在问我需要研究哪些方面来摆脱错误。我是新手,我发现它很难。

我使用myphpadmin在wampserver上运行它,这可能导致我的任何困难,还是我编写代码的方式?

1 个答案:

答案 0 :(得分:1)

如果在PHP中期望它们之前在这些输入字段中逐字添加name=""怎么样?

 <LABEL for="firstname">First Name: </LABEL>
          <INPUT type="text" name="firstname" id="firstname" size="20">
 <LABEL for="lastname">Last Name: </LABEL>
          <INPUT type="text" name="lastname" id="lastname" size="20"><BR><br>
 Date of Birth (DOB): <input type="date" name="dob"> <LABEL for="email">   Email: </LABEL>
          <INPUT type="email" name="email" id="email" size="30"><br>