the global variable level scope, i'm trying implement delete function, , inside delete query global variable replacing table name, code below, when test before user click 'delete' it's defined, when after clicking button, variable undefined.
the $globals['$table']
been filled user, in different function, , when echo $globals['$table']
first, shows me value, , it's fine.
<?php function deleteoption() { include ('../ciecon.php'); echo "<form action= 'delete.php' method = 'post'>"; echo $globals['$table']; if (isset($_post['delete'])) { if (empty($_post['id']) || $_post['id'] == 0) { echo "<h4> please choose delete </h4>"; echo $globals['$table'] . "hmmmm"; } else { $impid = implode("' , '", $_post['id']); $sqldelete = "delete " . $globals['$table'] . " id in ('" . $impid . "')"; $deletequery = mysqli_query($dbcie, $sqldelete) or die("error : " . mysqli_error($dbcie)); } } // end of delete... else { echo ""; } echo "</form >"; }; // end of delete function..
this how $globle['table'] has been defined user
<?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)); //trying this... $_session["tbl"] = $globals['$table']; /// 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> <input type='checkbox' name='table[]' value='". $globals['$table'] ."' /> </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=""; } else { } /// };// end of function selectoption
i see trying concept of session variables. here how it:
at top of php file, right below line:
$globals['$table']="";
add this:
session_start(); if (isset($_session['table'])) { $globals['$table'] = $_session['table']; } // rest of php code...
then in function selectoption, right after this:
switch($lists) { ... }
add following line:
$_session['table'] = $globals['$table'];
this way keep selected table alive across requests.
i urge however, rewrite code , better separate part output html part initialise variables , execute sql. better separate these two, easier maintain code.
Comments
Post a Comment