这是addStudent.php。 我应该怎么做,当管理员(我)添加新学生时,不要有重复的IdNumber。对不起,我尝试了一些我在网上看到的样品,但它不起作用。对不起初学者。如果您需要sql,请告诉我。
addStudent.php
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
include "connection.php";
if(isset($_POST['submit']))
{
$IDNumber = mysqli_real_escape_string($db, $_POST['IDNumber']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$lastname = mysqli_real_escape_string($db, $_POST['lastname']);
$firstname = mysqli_real_escape_string($db, $_POST['firstname']);
$middlename = mysqli_real_escape_string($db, $_POST['middlename']);
$course = mysqli_real_escape_string($db, $_POST['course']);
$year = mysqli_real_escape_string($db, $_POST['year']);
$birthdate = mysqli_real_escape_string($db, $_POST['birthdate']);
$gender = mysqli_real_escape_string($db, $_POST['gender']);
$citizenship = mysqli_real_escape_string($db, $_POST['citizenship']);
$religion = mysqli_real_escape_string($db, $_POST['religion']);
$birthplace = mysqli_real_escape_string($db, $_POST['birthplace']);
$nationality = mysqli_real_escape_string($db, $_POST['nationality']);
$home_add = mysqli_real_escape_string($db, $_POST['home_address']);
$home_no = mysqli_real_escape_string($db, $_POST['home_no']);
$bag_add = mysqli_real_escape_string($db, $_POST['baguio_add']);
$bag_no = mysqli_real_escape_string($db, $_POST['bag_no']);
$contactNumber = mysqli_real_escape_string($db, $_POST['contactNo']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$father = mysqli_real_escape_string($db, $_POST['father']);
$fatherOcc = mysqli_real_escape_string($db, $_POST['fatherOcc']);
$mother = mysqli_real_escape_string($db, $_POST['mother']);
$motherOcc = mysqli_real_escape_string($db, $_POST['motherOcc']);
$guardian = mysqli_real_escape_string($db, $_POST['guardian']);
$guardianAdd = mysqli_real_escape_string($db, $_POST['guardianAdd']);
$guardianRel = mysqli_real_escape_string($db, $_POST['guardianRel']);
$guardianNo = mysqli_real_escape_string($db, $_POST['guardianNo']);
//(IDNumber, password, lastname, firstname, middlename, course, year, birthdate,gender, citizenship, religion, Birthplace, Nationality, HomeAddress, homeNumber, BaguioAddress, BaguioNo, contactNo, email, father, fatherOcc, mother, motherOcc, guardian, guardianAdd, guardianRel, guardianNo)
$query1=mysqli_query($db, "insert into student (IDNumber, password, lastname, firstname, middlename, course, year, birthdate,gender, citizenship, religion, Birthplace, Nationality, HomeAddress, homeNumber, BaguioAddress, BaguioNo, contactNo, email, father, fatherOcc, mother, motherOcc, guardian, guardianAdd, guardianRel, guardianNo)
values(
'{$_POST['IDNumber']}',
'{$_POST['password']}',
'{$_POST['lastname']}',
'{$_POST['firstname']}',
'{$_POST['middlename']}',
'{$_POST['course']}',
'{$_POST['year']}',
'{$_POST['birthdate']}',
'{$_POST['gender']}',
'{$_POST['citizenship']}',
'{$_POST['religion']}',
'{$_POST['birthplace']}',
'{$_POST['nationality']}',
'{$_POST['home_address']}',
'{$_POST['home_no']}',
'{$_POST['baguio_add']}',
'{$_POST['bag_no']}',
'{$_POST['contactNo']}',
'{$_POST['email']}',
'{$_POST['father']}',
'{$_POST['fatherOcc']}',
'{$_POST['mother']}',
'{$_POST['motherOcc']}',
'{$_POST['guardian']}',
'{$_POST['guardianAdd']}',
'{$_POST['guardianRel']}',
'{$_POST['guardianNo']}'
)");
if($query1)
{
header("Location: viewStudent.php");
}
}
?>
<h4>Add Student</h4>
<form action="" method="post">
<p>ID Number:<input type="text" required="required" name="IDNumber" maxlength="7" onkeypress="return isNumberKey(event)" onkeyup="nospaces(this)">
<p>Password:<input type="text" required="required" name="password" placeholder="6-10 characters" maxlength="10" onkeyup="nospaces(this)">
<p>Last Name:<input type="text" required="required" name="lastname" maxlength="20" onkeypress="return ValidateAlpha(event)" onkeyup="nospaces(this)">
<p>First Name:<input type="text" required="required" name="firstname" maxlength="20" onkeypress="return ValidateAlpha(event)" onkeyup="nospaces(this)">
<p>Middle Name:<input type="text" required="required" name="middlename" maxlength="20" onkeypress="return ValidateAlpha(event)" onkeyup="nospaces(this)">
<p>Course:
<select name="course">
<option value="Associate in Accounting Technology (AAT)">Associate in Accounting Technology (AAT)</option>
<option value="Bachelor of Science in Acccountancy (BSAc)">Bachelor of Science in Acccountancy (BSAc)</option>
<option value="Bachelor of Science in Business Administration major in Business Economics (BSBA Bus Econ)">Bachelor of Science in Business Administration major in Business Economics (BSBA Bus Econ)</option>
<option value="Bachelor of Science in Business Administration major in Financial Management (BSBA FinMan)">Bachelor of Science in Business Administration major in Financial Management (BSBA FinMan)</option>
<option value="Bachelor of Science in Business Administration major in Human Resource Management Development (BSBA HRDM)">Bachelor of Science in Business Administration major in Human Resource Management Development (BSBA HRDM)</option>
<option value="Bachelor of Science in Business Administration major in Marketing (BSBA Mktg)">Bachelor of Science in Business Administration major in Marketing (BSBA Mktg)</option>
<option value="Bachelor of Science in Entrepreneurship (BS Entrep)">Bachelor of Science in Entrepreneurship (BS Entrep)</option>
<option value="Bachelor of Science in Hospitality and Tourism Management major in Hotel, Resort and Restaurant Management (BSHTM HRMM">Bachelor of Science in Hospitality and Tourism Management major in Hotel, Resort and Restaurant Management (BSHTM HRMM</option>
<option value="Bachelor of Science in Hospitality and Tourism Management major in Travel and Tours Management (BSHTM TTM)">Bachelor of Science in Hospitality and Tourism Management major in Travel and Tours Management (BSHTM TTM)</option>
<option value="Bachelor of Science in Management Accountancy (BSMA)">Bachelor of Science in Management Accountancy (BSMA)</option>
<option value="Bachelor of Science in Computer Science (BSCS)">Bachelor of Science in Computer Science (BSCS)</option>
<option value="Bachelor of Science in Information Technology (BSIT)">Bachelor of Science in Information Technology (BSIT)</option>
<option value="Bachelor of Science in Information Management (BSIS)">Bachelor of Science in Information Management (BSIS)</option>
<option value="Bachelor of Science in Mathematics (BS Math)">Bachelor of Science in Mathematics (BS Math)</option>
<option value="Bachelor of Library and Information Science (BLIS)">Bachelor of Library and Information Science (BLIS)</option>
<option value="Bachelor of Science in Architecture (BS Arch)">Bachelor of Science in Architecture (BS Arch)</option>
<option value="Bachelor of Science in Chemical Engineering (BSChE)">Bachelor of Science in Chemical Engineering (BSChE)</option>
<option value="Bachelor of Science in Civil Engineering (BSCE)">Bachelor of Science in Civil Engineering (BSCE)</option>
<option value="Bachelor of Science in Electrical Engineering (BSEE)">Bachelor of Science in Electrical Engineering (BSEE)</option>
<option value="Bachelor of Science in Electronics Engineering (BSECE)">Bachelor of Science in Electronics Engineering (BSECE)</option>
<option value="Bachelor of Science in Geodetic Engineering (BSGE)">Bachelor of Science in Geodetic Engineering (BSGE)</option>
<option value="Bachelor of Science in Industrial Engineering (BSIE)">Bachelor of Science in Industrial Engineering (BSIE)</option>
<option value="Bachelor of Science in Mechanical Engineering (BSME)">Bachelor of Science in Mechanical Engineering (BSME)</option>
<option value="Bachelor of Science in Mechatronics Engineering (BS MecE)">Bachelor of Science in Mechatronics Engineering (BS MecE)</option>
<option value="Bachelor of Science in Mining Engineering (BSEM)">Bachelor of Science in Mining Engineering (BSEM)</option>
<option value="Bachelor of Arts in Communication (BA Com)">Bachelor of Arts in Communication (BA Com)</option>
<option value="Bachelor of Arts in English (BA Engl)">Bachelor of Arts in English (BA Engl)</option>
<option value="Bachelor of Arts in Legal Studies (BA LS)">Bachelor of Arts in Legal Studies (BA LS)</option>
<option value="Bachelor of Arts in Philosophy and Interdisciplinary Studies (BA PIS)">Bachelor of Arts in Philosophy and Interdisciplinary Studies (BA PIS)</option>
<option value="Bachelor of Arts in Political Science (BA Polit Sc)">Bachelor of Arts in Political Science (BA Polit Sc)</option>
<option value="Bachelor of Arts in Religious and Values Studies (BARVS)">Bachelor of Arts in Religious and Values Studies (BARVS)</option>
<option value="Bachelor of Science in Psychology (BS Psych)">Bachelor of Science in Psychology (BS Psych)</option>
<option value="Bachelor of Science in Social Work (BS Sol Wk)">Bachelor of Science in Social Work (BS Sol Wk)</option>
<option value="Bachelor of Science in Nursing (BSN)">Bachelor of Science in Nursing (BSN)</option>
<option value="Bachelor in Medical Laboratory Science(BMLS)">Bachelor in Medical Laboratory Science(BMLS)</option>
<option value="Bachelor of Science in Biology (BS Biol)">Bachelor of Science in Biology (BS Biol)</option>
<option value="Bachelor of Science in Pharmacy (BS Pharm)">Bachelor of Science in Pharmacy (BS Pharm)</option>
<option value="Bachelor of Science in Radiologic Technology (BSRT)">Bachelor of Science in Radiologic Technology (BSRT)</option>
<option value="Bachelor of Elementary Education with specialization in General Education (BEED Gen Ed)">Bachelor of Elementary Education with specialization in General Education (BEED Gen Ed)</option>
<option value="Bachelor of Elementary Education with specialization in Pre-School Education (BEED Pre Schl)">Bachelor of Elementary Education with specialization in Pre-School Education (BEED Pre Schl)</option>
<option value="Bachelor of Elementary Education with specialization in Special Education (BEED SPED)">Bachelor of Elementary Education with specialization in Special Education (BEED SPED)</option>
<option value="Bachelor of Elementary Educ major in Tech & He (BEED THE)">Bachelor of Elementary Educ major in Tech & He (BEED THE)</option>
<option value="Bachelor of Elementary Educ major in Values Educ (BEED VAL)">Bachelor of Elementary Educ major in Values Educ (BEED VAL)</option>
<option value="Bachelor of Secondary Education major in Biological Sciences (BSED Biol Sc)">Bachelor of Secondary Education major in Biological Sciences (BSED Biol Sc)</option>
<option value="Bachelor of Secondary Education major in English (BSED Engl)">Bachelor of Secondary Education major in English (BSED Engl)</option>
<option value="Bachelor of Secondary Education major in Filipino (BSED Fil)">Bachelor of Secondary Education major in Filipino (BSED Fil)</option>
<option value="Bachelor of Secondary Education major in Filipino (BSED Fil)">Bachelor of Secondary Education major in Filipino (BSED Fil)</option>
<option value="Bachelor of Secondary Education major in Mathematics (BSED Math)">Bachelor of Secondary Education major in Mathematics (BSED Math)</option>
<option value="Bachelor of Secondary Education major in Musics, Arts, Physical Education, and Health (BSED MAPEH)">Bachelor of Secondary Education major in Musics, Arts, Physical Education, and Health (BSED MAPEH)</option>
<option value="Bachelor of Secondary Education major in Physical Sciences (BSED Phys Sc)">Bachelor of Secondary Education major in Physical Sciences (BSED Phys Sc)</option>
<option value="Bachelor of Secondary Education major in Social Studies (BSED Soc Stds)">Bachelor of Secondary Education major in Social Studies (BSED Soc Stds)</option>
</select>
<p>Year:<input type="number" max="5" min="1" required="required" name="year" onkeypress="return isNumberKey(event)"><br>
<p>Birthdate:<input type="date" required="required" name="birthdate" max= '<?php echo date('Y') - 14; ?>-01-01' min="1990-01-01"><br>
<p>Gender:<input type="radio" name="gender" required="required"
<?php if (isset($gender) && $gender=="female") //echo "checked";?>
value="female">Female
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") //echo "checked";?>
value="male">Male
<p>Citizenship:<input type="text" required="required" name="citizenship" maxlength="20" onkeypress="return ValidateAlpha(event)" onkeyup="nospaces(this)" /><br>
<p>Religion:
<select name="religion">
<option value="Aglipay">Aglipay</option>
<option value="Born Again">Born Again</option>
<option value="Iglesia ni Cristo">Iglesia ni Cristo</option>
<option value="Islam">Islam</option>
<option value="Jehovah's Witness">Jehovah's Witness</option>
<option value="Methodist">Methodist</option>
<option value="Mormon">Mormon</option>
<option value="Pentecost">Pentecost</option>
<option value="Protestant">Protestant</option>
<option value="Roman Catholic">Roman Catholic</option>
<option value="Others">Others</option>
<option value="Others">N/A</option>
</select>
<p>Birth Place:<input type="text" required="required" name="birthplace" maxlength="150" required pattern="[a-zA-Z0-9]+[a-zA-Z0-9 ]+"/>
<p>Nationality:<input type="text" required="required" name="nationality" maxlength="20" onkeypress="return ValidateAlpha(event)" onkeyup="nospaces(this)">
<p>Home Address:<input type="text" required="required" name="home_address" maxlength="150" required pattern="[a-zA-Z0-9]+[a-zA-Z0-9 ]+"/>
<p>Home ContactNo.:<input type="text" required="required" name="home_no" maxlength="11" onkeypress="return isNumberKey(event)" onkeyup="nospaces(this)"/>
<p>Baguio Address:<input type="text" required="required" name="baguio_add" maxlength="150" required pattern="[a-zA-Z0-9]+[a-zA-Z0-9 ]+">
<p>Baguio Contact No.:<input type="text" required="required" name="bag_no" maxlength="11" onkeypress="return isNumberKey(event)" onkeyup="nospaces(this)"/>
<p>Contact No.:<input type="text" required="required" name="contactNo" maxlength="11" onkeypress="return isNumberKey(event)" onkeyup="nospaces(this)"/>
<p>email:<input type="email" required="required" name="email">
<p>Name of Father:<input type="text" name="father" maxlength="20" pattern="[a-zA-Z]+[a-zA-Z ]+"/>
<p>Occupation of Father:<input type="text" name="fatherOcc" maxlength="30" onkeypress="return ValidateAlpha(event)" onkeyup="nospaces(this)"/>
<p>Name of Mother:<input type="text" name="mother" maxlength="20" pattern="[a-zA-Z]+[a-zA-Z ]+"/>
<p>Occupation of Mother:<input type="text" name="motherOcc" maxlength="30" onkeypress="return ValidateAlpha(event)" onkeyup="nospaces(this)"/>
<p>Guardian:<input type="text" name="guardian" maxlength="20" pattern="[a-zA-Z]+[a-zA-Z ]+"/>
<p>Guardian Address:<input type="text" name="guardianAdd" maxlength="150" required pattern="[a-zA-Z0-9]+[a-zA-Z0-9 ]+"/>
<p>Relationship With Guardian:<input type="text" name="guardianRel" maxlength="20" onkeypress="return ValidateAlpha(event)" onkeyup="nospaces(this)"/>
<p>Guardian Contact No.:<input type="text" name="guardianNo" maxlength="11" onkeypress="return isNumberKey(event)" onkeyup="nospaces(this)">
<p><input type="submit" name="submit">
</form>
</p>
</article>
<div class="clear"></div>
</div>
<footer>
<p>©Saint Louis University 2015 </p>
</footer>
<script type="application/javascript">
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
<script type="text/javascript">
function ValidateAlpha(evt)
{
var keyCode = (evt.which) ? evt.which : evt.keyCode
if ((keyCode < 65 || keyCode > 90) && (keyCode < 97 || keyCode > 123) && keyCode != 32)
return false;
return true;
}
</script>
<script type="text/javascript">
function nospaces(t){
if(t.value.match(/\s/g)){
t.value=t.value.replace(/\s/g,'');
}
}
</script>
<script type="text/javascript">
function alpha(e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}
</script>