evillz_inn Posted June 11, 2015 Share Posted June 11, 2015 When i click edit button of second table table field is not update please help ... empdetail.php <?php include("Config/config.php"); ?> <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script src="js/script.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="css/nav.css" rel="stylesheet" > <link href="css/bootstrap.min.css" rel="stylesheet"> <style> header{ color: #4d5858; background-color: #fffffe; } body { font-family:Arial, Helvetica, sans-serif; font-size:14px; } </style> <header> <title>SVIS: New Employee</title> <center><h1>SMART VEHICLE IDENTIFICATION SYSTEM</h1></center> </header> <body onload="viewdata()" bgcolor="#484848"> <div id='cssmenu'> <ul> <li class='active'><a href='index.php'>Employee Portal</a> <ul> <li class='active'><a href='#'>Employee Portal</a> <ul> <li><a href='newemp.php'>Add New Employee</a></li> <li class='active'><a href='empdetail.php'>Employee Details</a></li> </ul> </li> </ul> </li> <li><a href='#'>Toll Booth Portal</a> <ul> <li><a href='#'>Toll Booth</a> <ul> <li><a href='toll.php'>Add New Toll Booth</a></li> <li><a href='tolldetail.php'>Toll Booth Detials</a></li> </ul> </li> </ul> </li> <li><a href='#'>Vehicle Portal</a> <ul> <li><a href='#'>Vehicle Types</a> <ul> <li><a href='twowheel.html'>Two Wheel</a></li> <li><a href='fourwheel.html'>Four Wheel</a></li> </ul> </li> </ul> </li> <li><a href='#'>Owner</a> <ul> <li><a href='#'>Vehicle Owner</a> <ul> <li><a href='ownership.html'>Ownership</a></li> <li><a href='autowner.html'>Authorize Owner</a></li> </ul> </li> </ul> </li> <li><a href='settings.html'>Settings</a></li> <li><a href='#'>Log out</a></li> </ul> </div> <div style="margin:0 auto; width:980px; padding:10px; background-color:#dedede; height:800px;"> <h2 style="color: dimgray" >Employee Details</h2><br /><br/> <p><br/></p> <div class="container"> <div id="viewdata"></div> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="js/jquery-2.1.3.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/bootstrap.min.js"></script> <!-- jQuery Ajax --> <script type="text/javascript"> function viewdata(){ $.ajax({ type: "GET", url: "empdetail_getdata.php", dataType: "html" }).done(function( msg ) { $( "#viewdata" ).html( msg ); }).fail(function( jqXHR, textStatus ) { alert( "Request failed: " + textStatus ); }); } function updatedata(str){ var id = str; var un = $('#un'+str).val(); var pwd = $('#pwd'+str).val(); var cpwd = $('#cpwd'+str).val(); var fn = $('#fn'+str).val(); var ln = $('#ln'+str).val(); var em = $('#em'+str).val(); var reem = $('#reem'+str).val(); var dob = $('#dob'+str).val(); var gen = $('#gen'+str).val(); var ms = $('#ms'+str).val(); var nal = $('#nal'+str).val(); var pro = $('#pro'+str).val(); var ci = $('#ci'+str).val(); var nic = $('#nic'+str).val(); var datas = "id="+id+"&un="+un+"&pwd="+pwd+"&cpwd="+cpwd+"&fn="+fn+"&ln="+ln+"&em="+em+"&reem="+reem+"&dob="+dob+"&gen="+gen+"&ms="+ms+"&nal="+nal+"&pro="+pro+"&ci="+ci+"&nic="+nic; $.ajax({ type: "POST", url: "empdetail_updatedata.php", data: datas, dataType: "html" }).done(function( msg ) { alert( msg ); viewdata(); }).fail(function() { alert( "error" ); }).always(function() { alert( "finished" ); }); } </script> </body> </html> empdetail_getdata.php <table class="table table-condensed table-bordered table-hover table-striped"> <tr> <th>ID</th> <th>Username</th> <th>Password</th> <th>Confirm Password</th> <th>First Name</th> <th>last Name</th> <th>Email</th> <th>Re-Enter Email</th> </tr> <?php /** * Created by PhpStorm. * User: Hassan * Date: 6/11/2015 * Time: 12:26 PM */ include "Config/config.php"; $res = $connect->query("SELECT * FROM emp"); while($row = $res->fetch_assoc()): ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['username']; ?></td> <td><?php echo $row['password']; ?></td> <td><?php echo $row['conpassword']; ?></td> <td><?php echo $row['first_name']; ?></td> <td><?php echo $row['last_name']; ?></td> <td><?php echo $row['email']; ?></td> <td><?php echo $row['re_email']; ?></td> <td><a style="text-decoration:none;cursor:pointer;color:#aa5500;" data-toggle="modal" data-target="#addData-<?php echo $row['id']; ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a> </td> </tr> <!-- Modal --> <div class="modal fade" id="addData-<?php echo $row['id']; ?>" tabindex="-<?php echo $row['id']; ?>" role="dialog" aria-labelledby="myModalLabel-<?php echo $row['id']; ?>" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <form> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel-<?php echo $row['id']; ?>">Update Data</h4> </div> <div class="modal-body"> <input type="hidden" id="id" value="<?php echo $row['id']; ?>"> <div class="form-group"> <label for="un">Username</label> <input type="text" class="form-control" id="un<?php echo $row['id']; ?>" value="<?php echo $row['username']; ?>"> </div> <div class="form-group"> <label for="pwd">Password</label> <input type="text" class="form-control" id="pwd<?php echo $row['id']; ?>" value="<?php echo $row['password']; ?>"> </div> <div class="form-group"> <label for="cpwd">Confirm Password</label> <input type="text" class="form-control" id="cpwd<?php echo $row['id']; ?>" value="<?php echo $row['conpassword']; ?>"> </div> <div class="form-group"> <label for="fn">First Name</label> <input type="text" class="form-control" id="fn<?php echo $row['id']; ?>" value="<?php echo $row['first_name']; ?>"> </div> <div class="form-group"> <label for="ln">Last Name</label> <input type="text" class="form-control" id="ln<?php echo $row['id']; ?>" value="<?php echo $row['last_name']; ?>"> </div> <div class="form-group"> <label for="em">Email</label> <input type="text" class="form-control" id="em<?php echo $row['id']; ?>" value="<?php echo $row['email']; ?>"> </div> <div class="form-group"> <label for="reem">Re-Enter Email</label> <input type="text" class="form-control" id="reem<?php echo $row['id']; ?>" value="<?php echo $row['re_email']; ?>"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" onclick="updatedata('<?php echo $row['id']; ?>')" class="btn btn-primary">Save changes</button> </div> </form> </div> </div> </div> <?php /** * Created by PhpStorm. * User: Hassan * Date: 6/11/2015 * Time: 12:26 PM */ endwhile; ?> </table> <br><br> <table class="table table-condensed table-bordered table-hover table-striped"> <tr> <th>D.O.B</th> <th>Gender</th> <th>Marital Status</th> <th>Nationality</th> <th>Province</th> <th>City</th> <th>N.I.C</th> </tr> <?php /** * Created by PhpStorm. * User: Hassan * Date: 6/11/2015 * Time: 12:26 PM */ include "Config/config.php"; $res = $connect->query("SELECT * FROM emp"); while($row = $res->fetch_assoc()): ?> <tr> <td><?php echo $row['dob']; ?></td> <td><?php echo $row['gender']; ?></td> <td><?php echo $row['MaritalStatus']; ?></td> <td><?php echo $row['nationality']; ?></td> <td><?php echo $row['province']; ?></td> <td><?php echo $row['city']; ?></td> <td><?php echo $row['nic']; ?></td> <td><a style="text-decoration:none;cursor:pointer;color:#aa5500;" data-toggle="modal" data-target="#addData-<?php echo $row['id']; ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a> </td> </tr> <!-- Modal --> <div class="modal fade" id="addData-<?php echo $row['id']; ?>" tabindex="-<?php echo $row['id']; ?>" role="dialog" aria-labelledby="myModalLabel-<?php echo $row['id']; ?>" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content2"> <form> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel-<?php echo $row['id']; ?>">Update Data</h4> </div> <div class="modal-body"> <input type="hidden" id="id" value="<?php echo $row['id']; ?>"> <div class="form-group"> <label for="dob">D.O.B</label> <input type="text" class="form-control" id="dob<?php echo $row['id']; ?>" value="<?php echo $row['dob']; ?>"> </div> <div class="form-group"> <label for="gen">Gender</label> <input type="text" class="form-control" id="gen<?php echo $row['id']; ?>" value="<?php echo $row['gender']; ?>"> </div> <div class="form-group"> <label for="ms">Marital Status</label> <input type="text" class="form-control" id="ms<?php echo $row['id']; ?>" value="<?php echo $row['MaritalStatus']; ?>"> </div> <div class="form-group"> <label for="nal">Nationality</label> <input type="text" class="form-control" id="nal<?php echo $row['id']; ?>" value="<?php echo $row['nationality']; ?>"> </div> <div class="form-group"> <label for="pro">Province</label> <input type="text" class="form-control" id="pro<?php echo $row['id']; ?>" value="<?php echo $row['province']; ?>"> </div> <div class="form-group"> <label for="ci">city</label> <input type="text" class="form-control" id="ci<?php echo $row['id']; ?>" value="<?php echo $row['city']; ?>"> </div> <div class="form-group"> <label for="nic">N.I.C</label> <input type="text" class="form-control" id="nic<?php echo $row['id']; ?>" value="<?php echo $row['nic']; ?>"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" onclick="updatedata('<?php echo $row['id']; ?>')" class="btn btn-primary">Save changes</button> </div> </form> </div> </div> </div> <?php /** * Created by PhpStorm. * User: Hassan * Date: 6/11/2015 * Time: 12:26 PM */ endwhile; ?> </table> empdetail_updatedata.php <?php /** * Created by PhpStorm. * User: Hassan * Date: 6/11/2015 * Time: 12:26 PM */ include "Config/config.php"; $id = $_POST['id']; $un = $_POST['un']; $pwd = $_POST['pwd']; $cpwd = $_POST['cpwd']; $fn = $_POST['fn']; $ln = $_POST['ln']; $em = $_POST['em']; $reem = $_POST['reem']; $dob = $_POST['dob']; $gen = $_POST['gen']; $ms = $_POST['ms']; $nal = $_POST['nal']; $pro = $_POST['pro']; $ci = $_POST['ci']; $nic = $_POST['nic']; $cell = $_POST['cell']; $wrkh = $_POST['wrkh']; $sh = $_POST['sh']; $tid = $_POST['tid']; $f_n = $_POST['f_n']; $f_nic = $_POST['f_nic']; $f_pro = $_POST['f_pro']; if(isset($un) && isset($pwd) && isset($cpwd) && isset($fn) && isset($ln) && isset($em) && isset($reem) && isset($dob) && isset($gen) && isset($ms) && isset($nal) && isset($pro) && isset($ci) && isset($nic)){ $res2 = $connect->query("update emp set username='$un', password='$pwd', conpassword='$cpwd', first_name='$fn', last_name='$ln', email='$em', re_email='$reem', dob='$dob', gender='$gen', MaritalStatus='$ms', nationality='$nal', province='$pro', nic='$nic' where id='$id'"); if($res2){ echo "Success Update Data"; } else{ echo "Fail Update Data"; } } else{ echo "Error Update Data"; } ?> empdetail.php empdetail_getdata.php empdetail_updatedata.php bootstrap.css bootstrap.min.css bootstrap-theme.css bootstrap-theme.min.css Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted June 11, 2015 Share Posted June 11, 2015 That's too little information. Is it only the second column (username) that is not being updated? does the ajax call fail or succeed? what debugging have you done so far? does the form contain the element id's that it should? The more (relevant) info you give the better we all can help Quote Link to comment Share on other sites More sharing options...
evillz_inn Posted June 11, 2015 Author Share Posted June 11, 2015 Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted June 11, 2015 Share Posted June 11, 2015 when rendering your second table, you have the following: <input type="hidden" id="id" value="<?php echo $row['id']; ?>"> which will give every row the same id of "id". however, even if you appended the $id value you would then end up with each table containing an element with the same id for each row. you need to append your $id value to the input and also prefix each id input in each table and call that with the button. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.