first of of thank great website.
i'm in last year in college, , i'm working on web-site school. i've issue awhile , couldn't able fix it, thankful if guy me,
first, when admin login , go delete.php tap (he/she) have drop-list choose page go , click submit button show data in page, , there checkbox select next job listed, t choose job want delete, , click delete button, delete specified job.
my code works till when user choose , display data many tables, won't delete..
there 3 functions, selectoption()
, displayoption()
, deleteoption()
, issue how to add chosen table delete query ..
because if put table name , choose drop list work.. want optional user.
this code:
<?php include('../ciecon.php'); $globals['$table']=""; function displayoption(){ include('../ciecon.php'); echo ' <form action= "delete.php" method = "post"> <table width ="40%" cellpadding ="4" border="1" align="center" > <tr > <th style ="color: white; background-color: #f26822 ; " > select catagory delete </th> </tr>'; echo "<tr> <td>". "<select name = lists > <option name= nothing value= 0 selected >choose catagory</option> <option name= nothing value= 1> advertising </option> <option name= nothing value= 2> fiscal </option> <option name= nothing value= 3> food </option> <option name= nothing value= 4> shopping </option> <option name= nothing value= 5> rentals </option> <option name= nothing value= 6> setting </option> <option name= nothing value= 7> performances </option> <option name= nothing value= 8> registration/ushering </option> <option name= nothing value= 9> master of ceremonies </option> <option name= nothing value= 10> cleaning </option> <option name= nothing value= 11> others </option> </select>" ." </td> </tr>"; echo ' </table> <br/> <div align="center"> <input type="submit" name="submit" value="submit" /> <input type="reset" value="clear" /> <hr> <hr> </div> </form> '; /// }; function selectoption(){ include('../ciecon.php'); /// if(isset($_post['submit'])){ if(isset($_post['submit'])) // second submit { $errormessage = ""; if(($_post['lists'])== 0) // trying error if user don't choose. { $errormessage .= "<li>you forgot choose !</li>"; } $lists = $_post['lists']; // <-save info in variable based on user input if(!empty($errormessage)) { echo("<p>there error form:</p>\n"); echo("<ul>" . $errormessage . "</ul>\n"); die(); } } // end of second submit switch($lists) { case '1': $globals['$table'] ="advertising"; break; case '2': $globals['$table'] ="fiscal"; break; case '3': $globals['$table']="food"; break; case '4': $globals['$table'] ="shopping"; break; case '5': $globals['$table'] ="rentals"; break; case '6': $globals['$table'] ="settingup"; break; case '7': $globals['$table'] ="performances"; break; case '8': $globals['$table'] ="registration"; break; case '9': $globals['$table'] ="masterofceremonies"; break; case '10': $globals['$table'] ="cleaning"; break; case '11': $globals['$table']="others"; break; default; echo 'unsupported category'; break; } if ($globals['$table'] != ""){ $sql = "select * ". $globals['$table']. " "; $result = mysqli_query($dbcie, $sql) or die(mysqli_error($dbcie)); /// display info chosen database.../// echo " <form action= 'delete.php' method = 'post'> <table cellpadding ='4' border='1' width='80%' align='center'> <tr> <th>check </th> <th>job's name</th> <th>description</th> <th> no students needed</th> <th>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>"; echo "<td>" . $row['jobname'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $row['nostudent'] . "</td>"; echo "<td>" . $row['duedate'] . "</td>"; echo "</tr>"; } echo "</table>"; /// end search here.........../// echo " <br> <div align='center'> <input type='reset' value='clear' > <input type='submit' name='delete' value='delete'> </div> </form>"; } // end if !table=""; mysqli_close($dbcie); // } else { } /// };// end of function selectoption function deleteoption(){ include('../ciecon.php'); $tbl = $globals['$table'] ; echo $tbl ." beggning of function" ; if(isset($_post['delete'])) { if( empty($_post['id']) || $_post['id'] == 0 ){ echo"<h4> please choose delete </h4>"; }else{ echo "test 1: pass "; $impid = implode("' , '" , $_post['id']); echo $globals['$table']."before sql query" ; $sqldelete = "delete ". $globals['$table']. " id in ('" . $impid . "')"; $deletequery = mysqli_query($dbcie,$sqldelete) or die ("error : ".mysqli_error($dbcie)); } }// end of delete... }; // end of delete function.. function closedb(){}; ?> </style> <head><title> ..deletefff.. </title></head> deletefff.php <body> <!-- <a href= "../adminindex.php" > <button> main page </button></a> --> </body> </html>
instead of using global variable in delete query, not being set when doing delete post, pass in table name post when click delete.
you using $_post['id']
echo "<td> <input type='checkbox' name='id[]' value='". $row['id'] ."' /> </td>";
you same thing table name:
echo "<td> <input type='checkbox' name='table[]' value='". $globals['$table'] ."' /> </td>";
and can use in delete query $_post['table']
.
ideally you'd strip out use of globals everywhere (they bad idea generally), quickest solution.
Comments
Post a Comment