HTML form not updating mySQL through PHP file [SOLVED] -
i'm not quite sure what's going on because i'm following same concept of implementation on page several other pages on site. reason, page not update database. throws no errors or anything, doesn't update user information.
the html shows text box , radio buttons @ top admin user can type name , select whether promote, demote, activate, or deactivate account entered text box. once submitted, code doesn't yell @ me instead nothing. i've tried several different ways of doing no matter it's not updating database.
here html file (shortened):
<?php include_once ($_server['document_root'] . '/public_html/templates/areadmin.php'); if(isset($_post['user'])) { checkfunc(); } else { ?> <!-- contents of page--> <div class="container2"> <div align="center"><br/><br/> <div id="box1"><br/><br/><br/> <form action="?checkfunc" style="display:inline; margin:2px;" method="post"> <input type="text" autocomplete="off" size="15" placeholder="username" name="user"><br/> <input type="radio" name="act" value="promote">promote <input type="radio" name="act" value="demote">demote <input type="radio" name="act" value="activate">activate <input type="radio" name="act" value="deactivate">deactivate <br/><input type="submit" value="submit"> </form> <?php include_once ($_server['document_root'] . '/public_html/php/action.php'); listmembers($db_handle); ?> </table><br/><br/><br/><br/> </div> </div> </div> <?php } function checkfunc() { $selected = $_request['act']; if($selected == "promote") { promote($db_handle); } elseif($selected == "demote") { demote($db_handle); } elseif($selected == "activate") { activate($db_handle); } elseif($selected == "deactivate") { deactivate($db_handle); } } ?> functions php file:
$db_handle = mysqli_connect($server, $user_name, $pass_word, $database); //date: june 25, 2015 //description: promotes user admin function promote($db_handle) { //grabs info html $user = $_post['user']; //updates user admin mysqli_query($db_handle, "update `user` set isadmin = 1 username = '$user'"); header ("location: /public_html/html/memberlist.html"); } //date: june 25, 2015 //description: demotes user standard function demote($db_handle) { //grabs info html $user = $_post['user']; if($user != $_session['username'] && $user != "admin") { //updates user admin mysqli_query($db_handle, "update `user` set isadmin = 0 username = '$user'"); header ("location: /public_html/html/memberlist.html"); } else { echo "nope."; } } //date: june 25, 2015 //description: activates inactive account function activate($db_handle) { //grabs info html $user = $_post['user']; //updates user admin mysqli_query($db_handle, "update `user` set isactive = 1 username = '$user'"); header ("location: /public_html/html/memberlist.html"); } function deactivate($db_handle) { //grabs info html $user = $_post['user']; //updates user admin mysqli_query($db_handle, "update `user` set isactive = 0 username = '$user'"); header ("location: /public_html/html/memberlist.html"); } can tell me why database won't take update statements?
update:
with error handling telling me $db_handle undefined , null within .php functions, however, there on dozen functions in .php , of them have $db_handle parameter , work. listmembers($db_handle) used on same .html , isn't giving errors.
i solved issue creating new function in .php file check function needs run , passing global variable $db_handle.
html:
<?php include_once ($_server['document_root'] . '/public_html/templates/areadmin.php'); if(isset($_post['user'])) { checkfunc(); } else { ?> <!-- contents of page--> <div class="container2"> <div align="center"><br/><br/> <div id="box1"><br/><br/><br/> <form action="?checkfunc" style="display:inline; margin:2px;" method="post"> <input type="text" autocomplete="off" size="15" placeholder="username" name="user"><br/> <input type="radio" name="act" value="promote">promote <input type="radio" name="act" value="demote">demote <input type="radio" name="act" value="activate">activate <input type="radio" name="act" value="deactivate">deactivate <br/><input type="submit" value="submit"> </form> </div> </div> </div> <?php } function checkfunc() { include_once ($_server['document_root'] . '/public_html/php/action.php'); checkfunction($db_handle); } ?> php:
//author: lance rainey //date: june 25, 2015 //description: promotes user admin function checkfunction() { global $db_handle; $selected = $_request['act']; if($selected == "promote") { promote($db_handle); } elseif($selected == "demote") { demote($db_handle); } elseif($selected == "activate") { activate($db_handle); } elseif($selected == "deactivate") { deactivate($db_handle); } } //author: lance rainey //date: june 25, 2015 //description: promotes user admin function promote($db_handle) { //grabs info html $user = $_post['user']; $query = "update `user` set isadmin = 1 username = '$user'"; //updates user admin mysqli_query($db_handle, $query) or die(mysqli_error($db_handle)); header ("location: /public_html/html/memberlist.html"); } //author: lance rainey //date: june 25, 2015 //description: demotes user standard function demote($db_handle) { //grabs info html $user = $_post['user']; $query = "update `user` set isadmin = 0 username = '$user'"; if($user != $_session['username'] && $user != "admin") { //updates user admin mysqli_query($db_handle, $query) or die(mysqli_error($db_handle)); header ("location: /public_html/html/memberlist.html"); } else { echo "nope."; } } //author: lance rainey //date: june 25, 2015 //description: activates inactive account function activate($db_handle) { //grabs info html $user = $_post['user']; $query = "update `user` set isactive = 1 username = '$user'"; //updates user admin mysqli_query($db_handle, $query) or die(mysqli_error($db_handle)); header ("location: /public_html/html/memberlist.html"); } //author: lance rainey //date: june 25, 2015 //description: deactivates active account function deactivate($db_handle) { //grabs info html $user = $_post['user']; $query = "update `user` set isactive = 0 username = '$user'"; //updates user admin mysqli_query($db_handle, $query) or die(mysqli_error($db_handle)); header ("location: /public_html/html/memberlist.html"); } thank suggestions.
Comments
Post a Comment