Search code examples
phppostmysqlitwitter-bootstrap-2

post an update user's password using $_SERVER["SCRIPT_NAME"] return 500 (Internal Server Error)


i want to update user's password and place $_SERVER["SCRIPT_NAME"] so i can update without user go to another page. But im die trying. Here is..

history.php

<?php
$namamenu = $stat = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$namamenu = test_input($_POST["nameMenu"]);

if(!empty($_POST) && $namamenu="datalogin"){
    $pass = test_input($_POST["pass"]);
    $passnew1 = test_input($_POST["passnew1"]);
    $passnew2 = test_input($_POST["passnew2"]);
    $result = $conn->prepare("SELECT password FROM profile WHERE id=?");
    $result->bind_param('i', $getid);
    $result->execute();
    $result = $result->get_result();
    $result = $result->num_rows;
    if($result!=0){
        if($passnew1 == $passnew2){
            $result = $conn->prepare("UPDATE profile SET password=? WHERE id=?");
            $result->bind_param('si', $passnew1, $getid);
            $result->execute();
            if ($result == TRUE){
                $stat = "<div class='alert alert-success fade in'><a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a><strong>User: '".$getemail."' updated successfully</strong></div>";
                $result->close();
            }else{
                $stat = "<div class='alert alert-danger fade in'><a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a><strong>Error: </strong>".$conn->error."</div>";
            }
        }else{
            $stat = "<div class='alert alert-danger fade in'><a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a><strong>Password Not Match!</strong></div>";
        }
    }else{
        $stat = "<div class='alert alert-danger fade in'><a href='#' class='close' data-dismiss='alert' aria-label='close'></a><strong>Wrong Password!</strong></div>";
      }
  }

}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>

then i here is the user interface, btw im using bootstrap 2.x

<!-- DATA LOGIN -->
      <div class="tab-pane" id="datalogin">
        <div class="row">
            <div class="span2"></div>
            <div class="span8">
            <form role="form" name="frm_datalogin" method="POST" action="<?php echo htmlspecialchars($_SERVER["SCRIPT_NAME"]);?>">
                <div class="row">
                <center><h4>Form Data Login</h4></center>
                <div class="span4">
                <input type="hidden" name="nameMenu" value="datalogin">
                <div class="form-group">
                  <label for="email">Email: </label>
                  <input type="text" name="email" class="form-control" id="email" value="<?php echo $getemail; ?>" readonly>
                </div>
                </div>
                <div class="span4">
                <div class="form-group">
                  <label for="pass">Password: </label>
                  <input type="password" name="pass" class="form-control" id="pass" value="" placeholder="Enter your password" required >
                </div>
                <div class="form-group">
                  <label for="passnew1">New Password: </label>
                  <input type="password" name="passnew1" class="form-control" id="passnew1" value="" placeholder="Enter your password" required >
                </div>
                <div class="form-group">
                  <label for="passnew2">Enter New Password Again: </label>
                  <input type="password" name="passnew2" class="form-control" id="passnew2" value="" placeholder="Enter your password" required >
                </div>
                </div>
                </div>
              <br>
                <button type="submit" name="submit" class="btn btn-info btn-large btn-block">Submit <i class="icon-ok icon-white"></i></button>
                <?php echo "<div class='bg-danger'>$stat</div>";?>
            </form>
            <br>
            </div>
            <div class="span2"></div>
        </div>
      </div>

please kindly help me...any suggestion how im solve it?


Solution

  • lol my bad..put that

    function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
    }
    

    above anything...and done..thanks