<?php
if (isset($_GET['trn']) && $_GET['trn']=='UPDATE'){
echo '<button type="submit" class="btn btn-primary addOrder" name="UpdateBtn">Update list</button>';
}else{
echo '<button type="submit" class="btn btn-primary addOrder" name="AddOrder">Add list</button>';
}
?>
what am trying to say is when i click the update list button from the code above i expecting if (isset($_POST['UpdateBtn'])) to work but everytime i click nothing happened
if (isset($_POST['UpdateBtn'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$username = $_POST['username'];
$password = $_POST['password'];
$type = $_POST['type'];
updatelist($pdo,$id,$fname,$lname,$username,$password,$type);
}
i try this to see if it echo the hello world but still not working
if (isset($_POST['UpdateBtn'])){
echo "hello world";
}
this is my code for my function that save in other php files the rest of the code save in same files
function updatelist($pdo,$id,$fname,$lname,$username,$password,$type){
try {
$sql ='UPDATE users set fname=:fname, lname=:lname,username=:username,password=:password,type=:type WHERE id=:id';
$statement = $pdo->prepare($sql);
$statement->bindValue(':id',$id);
$statement->bindValue(':fname',$fname);
$statement->bindValue(':lname',$lname);
$statement->bindValue(':username',$username);
$statement->bindValue(':password',$password);
$statement->bindValue(':type',$type);
$statement->execute();
echo '<script>alert(" Order successfully updated")</script>';
echo '<script>window.location="page2.php"</script>';
}catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
$pdo = null;
$sql = null;
}
}
this is my code where i can insert a input
<div class="row inputRow">
<div class="row inputRow">
<div class="col-2">
<h5> first name<h5>
<input type="text" class="form-control" placeholder="fname" name="fname" value="<?php if (isset($_GET['trn']) && $_GET['trn']=='UPDATE'){ echo $fname;} ?>">
</div>
<div class="col-2">
<h5> last name<h5>
<input type="text" class="form-control" placeholder="lname" name="lname" value="<?php if (isset($_GET['trn']) && $_GET['trn']=='UPDATE'){ echo $lname;} ?>">
</div>
<div class="col-2">
<h5> username<h5>
<input type="text" class="form-control" placeholder="username" name="username" value="<?php if (isset($_GET['trn']) && $_GET['trn']=='UPDATE'){ echo $username;} ?>">
</div>
<div class="col-2">
<h5> password<h5>
<input type="text" class="form-control" placeholder="password" name="password" value="<?php if (isset($_GET['trn']) && $_GET['trn']=='UPDATE'){ echo $password;} ?>">
</div>
<div class="col-6">
<h5> User type<h5>
<select class="form-select" aria-label="Default select example" name="type">
<option value="administrator" <?php if (isset($_GET['trn']) && $_GET['trn']=='UPDATE' && $id=='administrator'){ echo 'selected';} ?>>administrator</option>
<option value="customer" <?php if (isset($_GET['trn']) && $_GET['trn']=='UPDATE' && $id =='customer'){ echo 'selected';} ?>>customer</option>
</select>
</div>
</div>
i already ask this to my previous question but i think i didn't properly explain what happened also i use this method in my other project and its work i dont know why in this its not am new in php
<form>
? (if you do please add it to your question)javascript
orcss
related?<form>
there and overlooked that