php dropdownlist undefined index

时间:2016-09-05 21:37:49

标签: php

我是PHP编程的新手,我在使用下拉列表的模块中。

  

遇到PHP错误严重性:通知消息:未定义索引:yos。

这是代码。我希望有人帮助我。

<?php

$servername="localhost";
$username="root";
$password="";
$dbname="online_voting_web";
//Create connection
$con=mysqli_connect($servername,$username,$password,$dbname);

$name       = $_POST['firstname'];
$name2      = $_POST['lastname'];
$name3      = $_POST['middlename'];
$username       = $_POST['username'];
$pass       = md5($_POST['password']);
$yos = isset($_POST['yos']) ? $_POST['yos'] : '';
$id         = $_POST['stud_id'];


if(!$name || !$name2 ||$name3 || $id || !$year || !$pass|| !$username){
$error="Please fill empty fields";
include"student_reg.php";
exit();
}
$sql = "SELECT stud_id FROM stud_name WHERE stud_id='$id'";
$query = mysqli_query($con,$sql)or die(mysqli_error($con));
$exist = mysqli_num_rows($query);

    if($exist==1){
    $nam="<center><h4><font color='#FF0000'>The student ID already   exist,register another</h4></center></font>";
    unset($id);
    include('student_reg.php');
    exit();
}
$sql = "SELECT stud_username FROM stud_user WHERE     username='".$_POST['username']."'";
$query = mysqli_query($con,$sql)or die(mysqli_error($con));
$exist = mysqli_num_rows($query);

    if($exist==1){
    $nam="<center><h4><font color='#FF0000'>The student ID already exist,register another</h4></center></font>";
    unset($id);
    include('student_reg.php');
    exit();

    }

$sql = "INSERT INTO stud_name(stud_id,studFname,stud_Lname,stud_Mname)
     VALUES('$id','$name','$name2','$name3')";
$sql2 = "INSERT INTO stud_course(stud_username,stud_year)
     VALUES('$username','$year')";
$sql3 = "INSERT INTO stud_user(stud_id,stud_username)
     VALUES('$id','$username')"; 
$sql4 = "INSERT INTO login_(username,password)
     VALUES('$username','$pass')";           

  $result = mysqli_query($con,$sql);
   $result2 = mysqli_query($con,$sql2);
 $result3 = mysqli_query($con,$sql3);
 $result4 = mysqli_query($con,$sql4);

if(!$result && !$result2 && !$result3 &&!$result4){
die("Error on mysql query".mysqli_error());
}
else{
header("location: index.php");
}

?>

这是我第一次使用单词yos

的另一种形式的代码的一部分
   <!--Style link-->
<link href="layout/styles/layout.css" rel="stylesheet" type="text/css">
<!--Navigation-->
 </div>
</div>
<body id="top">
<div class="wrapper row3">
<div class="rounded">
<main class="container clear"> 
  <div class="group btmspace-30"> 

    <div id="register">
<!--End of Navigation-->
    <fieldset>
        <legend><h3>Student Registration Form</h3></legend>
  <h4 style="color:#e60808;">
 <?php global $nam; echo $nam;?> </h4> 
 <?php global $error; echo $error;?>                  
        <!-- the login form-->
<form enctype="application/x-www-form-urlencoded" action="" method="post" id="myform">
            <div class="register">
            <table width="400px">
 <tr><td><label>Firstname</label></td>
<td><input type="text" name="firstname" value="" style="width:250px;    height:34px; border:1px solid #336666;"/></td>
 </tr>
 <tr><td><label>Middlename</label></td>
 <td><input type="text" name="middlename" value="" style="width:250px; height:34px; border:1px solid #336666;"/></td>
<tr><td><label>Lastname</label></td>
<td><input type="text" name="lastname" value="" style="width:250px; height:34px; border:1px solid #336666;"/></td>
 </tr>
 <tr><td><label>Username</label></td>
  <td><input type="text" name="username" value="" style="width:250px; height:34px; border:1px solid #336666;"/></td>
 </tr>
 <tr><td><label>Password</label></td>
  <td><input type="password" name="password" value="" style="width:250px; height:34px; border:1px solid #336666;"/></td>
</tr>
 <tr>
 <td><label>Year Level</label></td>
<td><select name="yos" id="yos" style="width:250px; height:34px; border:1px solid #336666;">
<option value="000">Choose Level</option>
<option value="G7">Grade 7</option>
<option value="G8">Grade 8</option>
<option value="G9">Grade 9</option>
<option value="G10">Grade 10</option>
<option value="G11a">Grade 11-GAS</option>
<option value="G11b">Grade 11-Blhablha</option>
<option value="G12a">Grade 12-Blahblah</option>
<option value="G12b">Grade 12-khfakhf</option>
</select></td>
 </tr>
<tr><td><label>ID Number</label></td>
<td><input type="text" name="stud_id" value="" style="width:250px; height:34px; border:1px solid #336666;"/></td>
 </tr>
 <tr><td colspan="2" align="center"><input type="submit" name="submit" value="Submit" style="width:100px; height:34px; border:1px solid #336666; border-radius:4px;"></td></tr>
             </table>
            </div>
 </form>
 <script type="text/javascript">
var frmvalidator = new Validator("myform"); 
frmvalidator.addValidation("firstname","req","Please enter student     firstname"); 
 frmvalidator.addValidation("firstname","maxlen=50");
    frmvalidator.addValidation("middlename","req","Please enter student   middlename"); 
  frmvalidator.addValidation("middlename","maxlen=50");
    frmvalidator.addValidation("lastname","req","Please enter student middlename"); 
   frmvalidator.addValidation("lastname","maxlen=50");
    frmvalidator.addValidation("username","req","Please enter student username"); 
   frmvalidator.addValidation("username","maxlen=50");
   frmvalidator.addValidation("password","req","Please enter student password"); 
   frmvalidator.addValidation("password","minlen=6","Password must not be less than 6 characters.");
    frmvalidator.addValidation("year","req","Please enter student year"); 
   frmvalidator.addValidation("year","dontselect=000","You don't select year");
   frmvalidator.addValidation("stud_id","req","Please enter your ID number"); 
    frmvalidator.addValidation("stud_id","maxlen=50");

    </fieldset>
    </div>

   

1 个答案:

答案 0 :(得分:0)

您应该确保密钥存在于$ _POST中,然后将其分配给变量:

$yos = isset($_POST['yos']) ? $_POST['yos'] : '';

这也不是错误,它只是一条通知消息,你可以跳过它