Hello fellow Stack Overflowers!
I have an issue with my my_admin.php file, my deletion buttons only process on firefox and no other browser, it's a tricky one, i thought it may have been my update to a new version of php but put back the original version and same issue :( If anyone can take a quick loot at my core code and see if they can spot an error. Code for my_admin is below. below that is pdocon.php and my functions.php all are included in the header of the my_admin.php file. Thanks anyone and everyone!
<?php include('includes/header.php'); ?>
<?php
//Include functions
include('includes/functions.php');
?>
<?php
/************** Fetching data from database using id ******************/
//require database class files
require('includes/pdocon.php');
//instatiating our database objects
$db = new Pdocon;
//Create a query to select all users to display in the table
$db->query("SELECT * FROM admin WHERE email=:email");
$email = $_SESSION['user_data']['email'];
$db->bindValue(':email', $email, PDO::PARAM_STR);
//Fetch all data and keep in a result set
$row = $db->fetchSingle();
?>
<div class="row">
<div class="col-md-12">
<h2 class="text-center">My Account</h2>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-9">
<?php showmsg(); ?>
<?php if ($row) { ?>
<form class="form-horizontal" role="form" method="post" action="">
<div class="form-group">
<label class="control-label col-sm-2" for="name" style="color:#f3f3f3;">Fullname:</label>
<div class="col-sm-10">
<input type="name" name="name" class="form-control" id="name" value="<?php echo $row['fullname'] ?>" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email" style="color:#f3f3f3;">Email:</label>
<div class="col-sm-10">
<input type="email" name="email" class="form-control" id="email" value="<?php echo $row['email'] ?>" required>
</div>
</div>
<div class="form-group ">
<label class="control-label col-sm-2" for="pwd" style="color:#f3f3f3;">Password:</label>
<div class="col-sm-10">
<fieldset disabled>
<input type="password" name="password" autocomplete="yes" class="form-control disabled" id="pwd" value="<?php echo $row['password'] ?>" required>
</fieldset>
</div>
</div>
<br>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<a class="btn btn-primary" href="edit_admin.php?admin_id=<?php echo $row['id'] ?>">Edit</a>
<button type="submit" class="btn btn-danger pull-right" name="delete_form">Delete</button>
</div>
</div>
</form>
</div>
<div class="col-md-3">
<a href="edit_admin.php?admin_id=<?php echo $row['id'] ?>">
<?php $image = $row['image']; ?>
<?php echo ' <img src="uploaded_image/' . $image . '" style="padding-top:25px; padding-bottom:30px;width:220px;-webkit-border-radius:50%;border-radius:50%;">'; ?>
</a>
</div>
<?php } ?>
<?php
/************** Deleting data from database when delete button is clicked ******************/
if (isset($_POST['delete_form'])) {
$admin_id = $_SESSION['user_data']['id'];
keepmsg('<div class="alert alert-danger text-center">
<strong>Confirm!</strong> Do you want to delete your account? <br>
<a href="#" class="btn btn-default" data-dismiss="alert" aria-label="close">No, Thanks</a><br>
<form action="my_admin.php" method="post" action="my_admin.php">
<input type="hidden" value="' . $admin_id . '" name="id"><br>
<input type="submit" name="delete" value="Yes, Delete" class="btn btn-danger">
</form>
</div>');
}
//If the Yes Delete (confim delete) button is click from the closable div proceed to delete
if (isset($_POST['delete'])) {
$id = $_POST['id'];
$db->query('DELETE FROM admin WHERE id=:id');
$db->bindValue(':id', $id, PDO::PARAM_INT);
$run = $db->execute();
if ($run) {
redirect('logout.php');
} else {
keepmsg('<div class="alert alert-danger text-center">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Sorry </strong>User with ID ' . $id . ' Could not be deleted
</div>');
}
}
?>
</div>
</div>
<?php include('includes/footer.php'); ?>
pdocon.php
<?php
class Pdocon
{
// The connection Properties
//Localhost Db information
private $host = "localhost";
private $user = "root";
private $pass = "";
private $dbnm = "wm_app";
//Online Db information
private $host = "localhost";
private $user = "whiteman_dbadmin";
private $pass = "dingleberries";
private $dbnm = "whiteman_wmdb";
private $dbh;
private $errmsg;
//Statement Handler
private $stmt;
//Method to open our connection
public function __construct()
{
$dsn = "mysql:host=" . $this->host . "; dbname=" . $this->dbnm;
$options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
try {
$this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
//echo "Successfully Connected";
} catch (PDOException $error) {
$this->errmsg = $error->getMessage();
echo $this->errmsg;
}
}
//Write query helper function using the stmt property
public function query($query)
{
$this->stmt = $this->dbh->prepare($query);
}
//Creating a bind function
public function bindvalue($param, $value, $type)
{
$this->stmt->bindValue($param, $value, $type);
}
//Function to execute statement
public function execute()
{
return $this->stmt->execute();
}
//Function to check if statement was successfully executed
public function confirm_result()
{
$this->dbh->lastInsertId();
}
//Command to fetch data in a result set in associative array
public function fetchMultiple()
{
$this->execute();
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
}
//Command count fetched data in a result set
public function fetchSingle()
{
$this->execute();
return $this->stmt->fetch(PDO::FETCH_ASSOC);
}
}
functions.php
<?php
//function to trim values
function cleandata($value)
{
return trim($value);
}
//function to sanitize value for string
function sanitize($raw_value)
{
return filter_var($raw_value, FILTER_SANITIZE_STRING);
}
//function to validate value for email
function valemail($raw_email)
{
return filter_var($raw_email, FILTER_VALIDATE_EMAIL);
}
//function to validate value for integer
function valint($raw_int)
{
return filter_var($raw_int, FILTER_VALIDATE_INT);
}
//function to redirect
function redirect($page)
{
header("Location: {$page}");
}
//function to keep error and success messages in a session
function keepmsg($message)
{
if (empty($message)) {
$message = "";
} else {
$_SESSION['msg'] = $message;
}
}
//function to display the stored message in the session super global
function showmsg()
{
if (isset($_SESSION['msg'])) {
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
}
//Create function to hash password using md5
function hashpassword($clean_password)
{
return md5($clean_password);
}