javascript - No duplicate entry for Idnumber in addStudent.php -
this addstudent.php. what should do, not have duplicate idnumber when admin(i) add new student. sorry tried samples saw in web not working. sorry beginner. if need sql let me know.
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 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 , tourism management major in hotel, resort , restaurant management (bshtm hrmm">bachelor of science in hospitality , tourism management major in hotel, resort , restaurant management (bshtm hrmm</option> <option value="bachelor of science in hospitality , tourism management major in travel , tours management (bshtm ttm)">bachelor of science in hospitality , tourism management major in travel , 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 , information science (blis)">bachelor of library , 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 , interdisciplinary studies (ba pis)">bachelor of arts in philosophy , 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 , values studies (barvs)">bachelor of arts in religious , 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 specialization in general education (beed gen ed)">bachelor of elementary education specialization in general education (beed gen ed)</option> <option value="bachelor of elementary education specialization in pre-school education (beed pre schl)">bachelor of elementary education specialization in pre-school education (beed pre schl)</option> <option value="bachelor of elementary education specialization in special education (beed sped)">bachelor of elementary education specialization in special education (beed sped)</option> <option value="bachelor of elementary educ major in tech & (beed the)">bachelor of elementary educ major in tech & (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, , health (bsed mapeh)">bachelor of secondary education major in musics, arts, physical education, , 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 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>
set id number primary key in database. add unique index.
this page shows how so.
Comments
Post a Comment