thanks great web-site, it's second time asking question, hope it's not ^^ i'm working on project, , i've got kind of weird issue update page, it's displaying data table in mysql, , when checkbox 2 rows update them new informations, copies new informations "(last row only)" , copy on other rows, , result , row become identical !!!! doing wrong ? please me guys code..
i when try update other row wont update, update last row...
<?php session_start(); if( isset($_session['username']) ){ include('../ciecon.php'); echo "<form action= 'admincleaning.php' method = 'post'>" ; if(isset($_post['update'])){ if( isset($_post['id']) ){ if( empty($_post['id']) || $_post['id'] == 0 ){ echo"<h4> please choose delete </h4>"; }else{ echo $implid = implode("' , '", $_post['id']); $sqlupdate = "update cleaning set jobname= '$_post[jobname]',description= '$_post[description]',nostudent='$_post[nostudent]',duedate='$_post[duedate]' id in('" . $implid . "')"; $resultupdate = mysqli_query($dbcie,$sqlupdate )or die(mysqli_error($dbcie)); if (mysqli_affected_rows($dbcie) > 0) { echo "you have updated data.<br><br>"; } else { echo "the data submitted matched current data nothing changed.<br><br>"; } } // end of else.. } // end of if isset($_post['id']) ... } // end of if isset($_post['update']) ... $sql = "select * cleaning "; $result = mysqli_query($dbcie, $sql) or die(mysqli_error($dbcie)); /// display info chosen database... echo " <table cellpadding ='4' border='1' width='80%' align='center'> <tr> <th class='tt' >check </th> <th class='tt'> job's name</th> <th class='tt' >description</th> <th class='tt' > no students needed</th> <th class='tt' >due date</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<br>"; echo "<tr>"; echo "<td> <input type='checkbox' name='id[]' value='". $row['id'] ."' /> </td>"; // array[] cause edit more 1 record... echo "<td><input type='text' name='jobname' value='" . $row['jobname'] . "'> </td>"; echo "<td><input type='text' name='description' value='" . $row['description'] . "'> </td>"; echo "<td><input type='text' name='nostudent' value='" . $row['nostudent'] . "'> </td>"; echo "<td><input type='text' name='duedate' value='" . $row['duedate'] . "'> </td>"; echo "</tr>"; } echo "</table>"; /// end search here........... echo " <br> <div align='center'> <input type='reset' value='clear' /> <input type='submit' name='update' value='update' /> </div> "; mysqli_close($dbcie); echo "</form>"; } else{echo "must logout see page..!!";} ?> <html> <head><title> ..cleanding.... </title></head> <style type="text/css"> body{ margin-top: 70px; /*space above table....*/ background-color: #23438e; } table{ background-color: white; } .tt{ background: #f26822; color: white ; } </style> <body> <!-- <a href= "../adminindex.php" > <button> main page </button></a> --> </body> </html>
the problem inputs have same name, , using in update, rather =
change input tags follow pattern:
<input type='text' name='jobname[".$row['id']."]' value='" . $row['jobname'] . "'>
and sql use pattern:
jobname= '$_post[jobname][$id]' ... id = $id
if more 1 id sent @ time, you'll need loop loop through inputs , run query.
each row of html table should sent server unique id, , each update should sent database appropriate data , id.
Comments
Post a Comment