Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I am trying to edit form values in php. Here is my html code of the form.
- <?php
- $connect = mysqli_connect("localhost", "root", "", "epanel");
- $id=$_POST['search'];
- $sql = "SELECT * FROM university WHERE uno= '$id'";
- $results1=mysqli_query($connect,$sql);
- while($ro=mysqli_fetch_array($results1))
- {
- $id=$ro[0];
- $name=$ro[1];
- $phone=$ro[2];
- $email=$ro[3];
- $address=$ro[4];
- $state=$ro[5];
- $pincode=$ro[6];
- }
- ?>
- <html>
- <body>
- <h1 style="color:black;"><u>Change University Details</u></h1></br>
- <form method="post" id="registration_form" action="uedit/enft">
- <table >
- </br>
- <tr>
- <td><input type="hidden" id="uid" name="uid" value="<?php echo "$id" ?>" size="30"/> <span id="j" /></span></td>
- </tr>
- <tr>
- <td><label for="uname"> Name</label></td>
- <td><input type="text" id="name" name="uname" value="<?php echo "$name" ?>" size="30"/> <span id="n" /></span></td>
- </tr>
- <tr>
- <td><label for="uphone">Phone_no</label></td>
- <td><input type="text" name="uphone" id="phn" value="<?php echo "$phone" ?>" size="30" width="20%"><span id="p" /></span></td>
- </tr>
- <tr >
- <td><label for="uemail">Email_Id</td>
- <td><input type="text" name="uemail" id="emailid" value="<?php echo "$email" ?>" size="30"><span id="e" /></span></td>
- </label>
- </tr>
- <tr>
- <td><label for="uaddress">Address</td>
- <td><input type="textarea" name="uaddress" id="add" value="<?php echo "$address" ?>" rows="10" cols="10"></textarea><span id="a"/></span></td>
- </tr>
- <tr>
- <td><label for="ustate">State</td>
- <td><select name="ustate" required>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "epanel";
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- $query="SELECT stname from state";
- $res=mysqli_query($conn,$query);
- foreach($res as $r)
- {
- ?>
- <option value="<?php echo $r['stname']; ?>"><?php echo $r['stname'];?></option>
- <?php
- }
- ?>
- </select>
- <span id="s" /></span></td>
- </tr>
- <tr>
- <td><label for="upincode">Pin_Code</td>
- <td><input type="text" name="upincode" id="pin" value="<?php echo "$pincode" ?>" size="30"><span id="k" /></span></td>
- </tr>
- <tr>
- <tr>
- <td><input type="submit" name="submit" value="UPDATE"></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- Here is the js code. Validations are not working properly, the form is being submitted even after some form values are not correct.
- <script>
- $("#n").hide();
- $("#p").hide();
- $("#e").hide();
- $("#a").hide();
- $("#k").hide();
- var name;
- var ph;
- var em;
- var a ;
- var pc;
- $("#name").focusout(function() {
- check_username();
- });
- $("#phn").focusout(function() {
- check_phone();
- });
- $("#emailid").focusout(function() {
- check_email();
- });
- $("#add").focusout(function() {
- check_add();
- });
- $("#pin").focusout(function() {
- check_pin();
- });
- function check_username() {
- var na= $("#name").val();
- var pat = new RegExp(/^[a-zA-Z ]+$/);
- if(pat.test(na)) {
- $("#n").hide();
- name=false;
- } else {
- $("#n").html("Invalid name");
- $("#n").show();
- name = true;
- }
- return name;
- }
- function check_phone() {
- var pho= $("#phn").val();
- var pat = new RegExp(/^[0-9]{8,11}$/);
- if(pat.test(pho)) {
- $("#p").hide();
- ph = false;
- } else {
- $("#p").html("Invalid Phone");
- $("#p").show();
- ph = true;
- }
- return ph;
- }
- function check_email() {
- var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/i);
- if(pattern.test($("#emailid").val())) {
- $("#e").hide();
- em = false;
- } else {
- $("#e").html("Invalid email address");
- $("#e").show();
- em = true;
- }
- return em;
- }
- function check_add() {
- var au = $("#add").val();
- var pat = new RegExp(/^[0-9a-zA-Z,/ -]+$/);
- if(pat.test(au)) {
- $("#a").hide();
- a = false;
- return a;
- } else {
- $("#a").html("Invalid address");
- $("#a").show();
- a = true;
- }
- return a;
- }
- function check_pin() {
- var pho= $("#pin").val();
- var pat = new RegExp(/^[1-9][0-9]{5}$/);
- if(pat.test(pho)) {
- $("#k").hide();
- pc = false;
- } else {
- $("#k").html("Invalid Pincode");
- $("#k").show();
- pc = true;
- }
- return pc;
- }
- $("#registration_form").submit(function() {
- var ne=check_username();
- var pe=check_phone();
- var eme=check_email();
- var ad=check_add();
- var che=check_pin();
- if (ne === 'false' && pe==='false' && eme==='false' && ad==='false' && che==='false')
- {
- return true;
- }
- else
- {
- return false;
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement